Skip to content

Commit 2a29733

Browse files
authored
Merge pull request #782 from thockin/release-3.x
Handle errors from credential refresh (v3)
2 parents dec45c3 + 93b8a38 commit 2a29733

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

cmd/git-sync/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,9 @@ func revIsHash(ctx context.Context, rev, gitRoot string) (bool, error) {
10831083
// syncRepo syncs the branch of a given repository to the destination at the given rev.
10841084
// returns (1) whether a change occured, (2) the new hash, and (3) an error if one happened
10851085
func syncRepo(ctx context.Context, repo, branch, rev string, depth int, gitRoot, dest string, refreshCreds func(context.Context) error, submoduleMode string) (bool, string, error) {
1086-
refreshCreds(ctx)
1086+
if err := refreshCreds(ctx); err != nil {
1087+
return false, "", fmt.Errorf("credential refresh failed: %w", err)
1088+
}
10871089

10881090
currentWorktreeGit := filepath.Join(dest, ".git")
10891091
var hash string

test_e2e.sh

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,9 +1093,9 @@ function e2e::auth_askpass_url_correct_password() {
10931093
}
10941094

10951095
##############################################
1096-
# Test askpass-url where the URL is flaky
1096+
# Test askpass-url where the URL is sometimes wrong
10971097
##############################################
1098-
function e2e::auth_askpass_url_flaky() {
1098+
function e2e::auth_askpass_url_sometimes_wrong() {
10991099
# run with askpass_url service which alternates good/bad replies.
11001100
HITLOG="$WORK/hitlog"
11011101
cat /dev/null > "$HITLOG"
@@ -1154,6 +1154,112 @@ function e2e::auth_askpass_url_flaky() {
11541154
assert_file_eq "$ROOT"/link/file "$FUNCNAME 1"
11551155
}
11561156

1157+
##############################################
1158+
# Test askpass-url where the URL is flaky
1159+
##############################################
1160+
function e2e::auth_askpass_url_flaky() {
1161+
# run with askpass_url service which alternates good/bad replies.
1162+
HITLOG="$WORK/hitlog"
1163+
cat /dev/null > "$HITLOG"
1164+
CTR=$(docker_run \
1165+
-v "$HITLOG":/var/log/hits \
1166+
e2e/test/ncsvr \
1167+
80 'read X
1168+
if [ -f /tmp/flag ]; then
1169+
echo "HTTP/1.1 200 OK"
1170+
echo
1171+
echo "username=my-username"
1172+
echo "password=my-password"
1173+
rm /tmp/flag
1174+
else
1175+
echo "HTTP/1.1 503 Service Unavailable"
1176+
echo
1177+
touch /tmp/flag
1178+
fi
1179+
')
1180+
IP=$(docker_ip "$CTR")
1181+
1182+
# First sync
1183+
echo "$FUNCNAME 1" > "$REPO/file"
1184+
git -C "$REPO" commit -qam "$FUNCNAME 1"
1185+
1186+
GIT_SYNC \
1187+
--git="/$ASKPASS_GIT" \
1188+
--askpass-url="http://$IP/git_askpass" \
1189+
--max-sync-failures=2 \
1190+
--wait=0.1 \
1191+
--repo="file://$REPO" \
1192+
--branch="$MAIN_BRANCH" \
1193+
--rev=HEAD \
1194+
--root="$ROOT" \
1195+
--dest="link" \
1196+
>> "$1" 2>&1 &
1197+
sleep 3
1198+
assert_link_exists "$ROOT/link"
1199+
assert_file_exists "$ROOT/link/file"
1200+
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
1201+
1202+
# Move HEAD forward
1203+
echo "$FUNCNAME 2" > "$REPO/file"
1204+
git -C "$REPO" commit -qam "$FUNCNAME 2"
1205+
sleep 3
1206+
assert_link_exists "$ROOT/link"
1207+
assert_file_exists "$ROOT/link/file"
1208+
assert_file_eq "$ROOT/link/file" "$FUNCNAME 2"
1209+
1210+
# Move HEAD backward
1211+
git -C "$REPO" reset -q --hard HEAD^
1212+
sleep 3
1213+
assert_link_exists "$ROOT/link"
1214+
assert_file_exists "$ROOT/link/file"
1215+
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
1216+
}
1217+
1218+
##############################################
1219+
# Test askpass-url where the URL fails at startup
1220+
##############################################
1221+
function e2e::auth_askpass_url_slow_start() {
1222+
# run with askpass_url service which takes a while to come up
1223+
HITLOG="$WORK/hitlog"
1224+
cat /dev/null > "$HITLOG"
1225+
CTR=$(docker_run \
1226+
-v "$HITLOG":/var/log/hits \
1227+
--entrypoint sh \
1228+
e2e/test/ncsvr \
1229+
-c "sleep 4;
1230+
/ncsvr.sh 80 'read X
1231+
echo \"HTTP/1.1 200 OK\"
1232+
echo
1233+
echo \"username=my-username\"
1234+
echo \"password=my-password\"
1235+
'")
1236+
IP=$(docker_ip "$CTR")
1237+
1238+
# Sync
1239+
echo "$FUNCNAME" > "$REPO/file"
1240+
git -C "$REPO" commit -qam "$FUNCNAME"
1241+
1242+
GIT_SYNC \
1243+
--git="/$ASKPASS_GIT" \
1244+
--askpass-url="http://$IP/git_askpass" \
1245+
--max-sync-failures=5 \
1246+
--wait=1 \
1247+
--repo="file://$REPO" \
1248+
--branch="$MAIN_BRANCH" \
1249+
--rev=HEAD \
1250+
--root="$ROOT" \
1251+
--dest="link" \
1252+
>> "$1" 2>&1 &
1253+
sleep 1
1254+
assert_file_absent "$ROOT/link"
1255+
1256+
sleep 5
1257+
assert_link_exists "$ROOT/link"
1258+
assert_file_exists "$ROOT/link/file"
1259+
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
1260+
}
1261+
1262+
11571263
##############################################
11581264
# Test exechook-success
11591265
##############################################

0 commit comments

Comments
 (0)