From 110bffbe1fe3c1b420bbf99f55be37bd4f1d3c58 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 1 May 2025 16:50:00 -0700 Subject: [PATCH 1/2] Make all of e2e use "local" for vars --- test_e2e.sh | 1068 +++++++++++++++++++++++++++------------------------ 1 file changed, 573 insertions(+), 495 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index 855e87c54..e8be4274d 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -108,16 +108,18 @@ function assert_file_contains() { } function assert_file_lines_eq() { - N=$(wc -l < "$1") - if (( "$N" != "$2" )); then - fail "$1 is not $2 lines: $N" + local n + n=$(wc -l < "$1") + if (( "$n" != "$2" )); then + fail "$1 is not $2 lines: $n" fi } function assert_file_lines_ge() { - N=$(wc -l < "$1") - if (( "$N" < "$2" )); then - fail "$1 is not at least $2 lines: $N" + local n + n=$(wc -l < "$1") + if (( "$n" < "$2" )); then + fail "$1 is not at least $2 lines: $n" fi } @@ -136,23 +138,23 @@ function assert_fail() { ( set +o errexit "$@" - RET=$? - if [[ "$RET" != 0 ]]; then + local ret=$? + if [[ "$ret" != 0 ]]; then return fi - fail "expected non-zero exit code, got $RET" + fail "expected non-zero exit code, got $ret" ) } # Helper: run a docker container. function docker_run() { - RM="--rm" + local rm="--rm" if [[ "${CLEANUP:-}" == 0 ]]; then - RM="" + rm="" fi docker run \ -d \ - ${RM} \ + ${rm} `# not quoted on purpose` \ --label git-sync-e2e="$RUNID" \ "$@" sleep 2 # wait for it to come up @@ -260,7 +262,7 @@ REPO="$DIR/repo" REPO2="${REPO}2" MAIN_BRANCH="e2e-branch" function init_repo() { - arg="${1}" + local arg="${1}" rm -rf "$REPO" mkdir -p "$REPO" @@ -328,13 +330,13 @@ METRIC_FETCH_COUNT='git_fetch_count_total' function GIT_SYNC() { #./bin/linux_amd64/git-sync "$@" - RM="--rm" + local rm="--rm" if [[ "${CLEANUP:-}" == 0 ]]; then - RM="" + rm="" fi docker run \ -i \ - ${RM} \ + ${rm} `# not quoted on purpose` \ --label git-sync-e2e="$RUNID" \ --network="host" \ -u git-sync:"$(id -g)" `# rely on GID, triggering "dubious ownership"` \ @@ -364,8 +366,8 @@ function GIT_SYNC() { function remove_containers() { sleep 2 # Let docker finish saving container metadata docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker kill "$CTR" >/dev/null + | while read -r ctr; do + docker kill "$ctr" >/dev/null done } @@ -679,8 +681,8 @@ function e2e::worktree_cleanup() { # suspend time so we can fake corruption docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker pause "$CTR" >/dev/null + | while read -r ctr; do + docker pause "$ctr" >/dev/null done # make a second commit @@ -689,9 +691,10 @@ function e2e::worktree_cleanup() { git -C "$REPO" commit -qam "${FUNCNAME[0]} new file" # make a worktree to collide with git-sync - SHA=$(git -C "$REPO" rev-list -n1 HEAD) - git -C "$REPO" worktree add -q "$ROOT/.worktrees/$SHA" -b e2e --no-checkout - chmod g+w "$ROOT/.worktrees/$SHA" + local sha + sha=$(git -C "$REPO" rev-list -n1 HEAD) + git -C "$REPO" worktree add -q "$ROOT/.worktrees/$sha" -b e2e --no-checkout + chmod g+w "$ROOT/.worktrees/$sha" # add some garbage mkdir -p "$ROOT/.worktrees/not_a_hash/subdir" @@ -699,8 +702,8 @@ function e2e::worktree_cleanup() { # resume time docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker unpause "$CTR" >/dev/null + | while read -r ctr; do + docker unpause "$ctr" >/dev/null done wait_for_sync "${MAXWAIT}" @@ -708,7 +711,7 @@ function e2e::worktree_cleanup() { assert_file_eq "$ROOT/link/file2" "${FUNCNAME[0]}-ok" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 2 assert_metric_eq "${METRIC_FETCH_COUNT}" 2 - assert_file_absent "$ROOT/.worktrees/$SHA" + assert_file_absent "$ROOT/.worktrees/$sha" assert_file_absent "$ROOT/.worktrees/not_a_hash" assert_file_absent "$ROOT/.worktrees/not_a_directory" } @@ -734,18 +737,19 @@ function e2e::worktree_unexpected_removal() { # suspend time so we can fake corruption docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker pause "$CTR" >/dev/null + | while read -r ctr; do + docker pause "$ctr" >/dev/null done # make a unexpected removal - WT=$(git -C "$REPO" rev-list -n1 HEAD) - rm -r "$ROOT/.worktrees/$WT" + local wt + wt=$(git -C "$REPO" rev-list -n1 HEAD) + rm -r "$ROOT/.worktrees/$wt" # resume time docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker unpause "$CTR" >/dev/null + | while read -r ctr; do + docker unpause "$ctr" >/dev/null done wait_for_sync "${MAXWAIT}" @@ -777,8 +781,8 @@ function e2e::sync_recover_wrong_worktree_hash() { # suspend time so we can fake corruption docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker pause "$CTR" >/dev/null + | while read -r ctr; do + docker pause "$ctr" >/dev/null done # Corrupt it @@ -787,8 +791,8 @@ function e2e::sync_recover_wrong_worktree_hash() { # resume time docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \ - | while read -r CTR; do - docker unpause "$CTR" >/dev/null + | while read -r ctr; do + docker unpause "$ctr" >/dev/null done wait_for_sync "${MAXWAIT}" @@ -805,7 +809,8 @@ function e2e::sync_recover_wrong_worktree_hash() { function e2e::stale_worktree_timeout() { echo "${FUNCNAME[0]} 1" > "$REPO"/file git -C "$REPO" commit -qam "${FUNCNAME[0]}" - WT1=$(git -C "$REPO" rev-list -n1 HEAD) + local wt1 + wt1=$(git -C "$REPO" rev-list -n1 HEAD) GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ @@ -825,80 +830,82 @@ function e2e::stale_worktree_timeout() { echo "${FUNCNAME[0]} 2" > "$REPO"/file2 git -C "$REPO" add file2 git -C "$REPO" commit -qam "${FUNCNAME[0]} new file" - WT2=$(git -C "$REPO" rev-list -n1 HEAD) + local wt2 + wt2=$(git -C "$REPO" rev-list -n1 HEAD) # wait for second sync wait_for_sync "${MAXWAIT}" - # at this point both WT1 and WT2 should exist, with - # link pointing to the new WT2 + # at this point both wt1 and wt2 should exist, with + # link pointing to the new wt2 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" - assert_file_exists "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" + assert_file_exists "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" # wait 2 seconds and make a third commit sleep 2 echo "${FUNCNAME[0]} 3" > "$REPO"/file3 git -C "$REPO" add file3 git -C "$REPO" commit -qam "${FUNCNAME[0]} new file" - WT3=$(git -C "$REPO" rev-list -n1 HEAD) + local wt3 + wt3=$(git -C "$REPO" rev-list -n1 HEAD) wait_for_sync "${MAXWAIT}" - # at this point WT1, WT2, WT3 should exist, with - # link pointing to WT3 + # at this point wt1, wt2, wt3 should exist, with + # link pointing to wt3 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_exists "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_exists "$ROOT/.worktrees/$WT2/file" - assert_file_exists "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" - - # wait for WT1 to go stale + assert_file_exists "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_exists "$ROOT/.worktrees/$wt2/file" + assert_file_exists "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" + + # wait for wt1 to go stale sleep 4 - # now WT1 should be stale and deleted, - # WT2 and WT3 should still exist + # now wt1 should be stale and deleted, + # wt2 and wt3 should still exist assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_absent "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_exists "$ROOT/.worktrees/$WT2/file" - assert_file_exists "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" - - # wait for WT2 to go stale + assert_file_absent "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_exists "$ROOT/.worktrees/$wt2/file" + assert_file_exists "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" + + # wait for wt2 to go stale sleep 2 - # now both WT1 and WT2 are stale, WT3 should be the only + # now both wt1 and wt2 are stale, wt3 should be the only # worktree left assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_absent "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_absent "$ROOT/.worktrees/$WT2/file" - assert_file_absent "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" + assert_file_absent "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_absent "$ROOT/.worktrees/$wt2/file" + assert_file_absent "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" } ############################################## @@ -907,7 +914,8 @@ function e2e::stale_worktree_timeout() { function e2e::stale_worktree_timeout_restart() { echo "${FUNCNAME[0]} 1" > "$REPO"/file git -C "$REPO" commit -qam "${FUNCNAME[0]}" - WT1=$(git -C "$REPO" rev-list -n1 HEAD) + local wt1 + wt1=$(git -C "$REPO" rev-list -n1 HEAD) GIT_SYNC \ --repo="file://$REPO" \ --root="$ROOT" \ @@ -923,7 +931,8 @@ function e2e::stale_worktree_timeout_restart() { echo "${FUNCNAME[0]} 2" > "$REPO"/file2 git -C "$REPO" add file2 git -C "$REPO" commit -qam "${FUNCNAME[0]} new file" - WT2=$(git -C "$REPO" rev-list -n1 HEAD) + local wt2 + wt2=$(git -C "$REPO" rev-list -n1 HEAD) # restart git-sync GIT_SYNC \ @@ -933,20 +942,21 @@ function e2e::stale_worktree_timeout_restart() { --stale-worktree-timeout="10s" \ --one-time - # at this point both WT1 and WT2 should exist, with - # link pointing to the new WT2 + # at this point both wt1 and wt2 should exist, with + # link pointing to the new wt2 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" - assert_file_exists "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" + assert_file_exists "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" # wait 2 seconds and make a third commit sleep 4 echo "${FUNCNAME[0]} 3" > "$REPO"/file3 git -C "$REPO" add file3 git -C "$REPO" commit -qam "${FUNCNAME[0]} new file" - WT3=$(git -C "$REPO" rev-list -n1 HEAD) + local wt3 + wt3=$(git -C "$REPO" rev-list -n1 HEAD) # restart git-sync GIT_SYNC \ @@ -956,23 +966,23 @@ function e2e::stale_worktree_timeout_restart() { --stale-worktree-timeout="10s" \ --one-time - # at this point WT1, WT2, WT3 should exist, with - # link pointing to WT3 + # at this point wt1, wt2, wt3 should exist, with + # link pointing to wt3 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_exists "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_exists "$ROOT/.worktrees/$WT2/file" - assert_file_exists "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" - - # wait for WT1 to go stale and restart git-sync + assert_file_exists "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_exists "$ROOT/.worktrees/$wt2/file" + assert_file_exists "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" + + # wait for wt1 to go stale and restart git-sync sleep 8 GIT_SYNC \ --repo="file://$REPO" \ @@ -981,23 +991,23 @@ function e2e::stale_worktree_timeout_restart() { --stale-worktree-timeout="10s" \ --one-time - # now WT1 should be stale and deleted, - # WT2 and WT3 should still exist + # now wt1 should be stale and deleted, + # wt2 and wt3 should still exist assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_absent "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_exists "$ROOT/.worktrees/$WT2/file" - assert_file_exists "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" - - # wait for WT2 to go stale and restart git-sync + assert_file_absent "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_exists "$ROOT/.worktrees/$wt2/file" + assert_file_exists "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" + + # wait for wt2 to go stale and restart git-sync sleep 4 GIT_SYNC \ --repo="file://$REPO" \ @@ -1006,21 +1016,21 @@ function e2e::stale_worktree_timeout_restart() { --stale-worktree-timeout="10s" \ --one-time - # now both WT1 and WT2 are stale, WT3 should be the only + # now both wt1 and wt2 are stale, wt3 should be the only # worktree left assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_exists "$ROOT/link/file2" assert_file_exists "$ROOT/link/file3" - assert_file_absent "$ROOT/.worktrees/$WT1/file" - assert_file_absent "$ROOT/.worktrees/$WT1/file2" - assert_file_absent "$ROOT/.worktrees/$WT1/file3" - assert_file_absent "$ROOT/.worktrees/$WT2/file" - assert_file_absent "$ROOT/.worktrees/$WT2/file2" - assert_file_absent "$ROOT/.worktrees/$WT2/file3" - assert_file_exists "$ROOT/.worktrees/$WT3/file" - assert_file_exists "$ROOT/.worktrees/$WT3/file2" - assert_file_exists "$ROOT/.worktrees/$WT3/file3" + assert_file_absent "$ROOT/.worktrees/$wt1/file" + assert_file_absent "$ROOT/.worktrees/$wt1/file2" + assert_file_absent "$ROOT/.worktrees/$wt1/file3" + assert_file_absent "$ROOT/.worktrees/$wt2/file" + assert_file_absent "$ROOT/.worktrees/$wt2/file2" + assert_file_absent "$ROOT/.worktrees/$wt2/file3" + assert_file_exists "$ROOT/.worktrees/$wt3/file" + assert_file_exists "$ROOT/.worktrees/$wt3/file2" + assert_file_exists "$ROOT/.worktrees/$wt3/file3" } ############################################## @@ -1042,10 +1052,12 @@ function e2e::v3_v4_upgrade_in_place() { assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1" # simulate v3's worktrees - WT="$(readlink "$ROOT/link")" - SHA="$(basename "$WT")" - mv -f "$ROOT/$WT" "$ROOT/$SHA" - ln -sf "$SHA" "$ROOT/link" + local wt + wt="$(readlink "$ROOT/link")" + local sha + sha="$(basename "$wt")" + mv -f "$ROOT/$wt" "$ROOT/$sha" + ln -sf "$sha" "$ROOT/link" # make a second commit echo "${FUNCNAME[0]} 2" > "$REPO/file2" @@ -1064,7 +1076,7 @@ function e2e::v3_v4_upgrade_in_place() { assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1" assert_file_exists "$ROOT/link/file2" assert_file_eq "$ROOT/link/file2" "${FUNCNAME[0]} 2" - assert_file_absent "$ROOT/$SHA" + assert_file_absent "$ROOT/$sha" } ############################################## @@ -1103,10 +1115,10 @@ function e2e::readlink() { # Test branch syncing ############################################## function e2e::sync_branch() { - OTHER_BRANCH="other-branch" + local other_branch="other-branch" # First sync - git -C "$REPO" checkout -q -b "$OTHER_BRANCH" + git -C "$REPO" checkout -q -b "$other_branch" echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" git -C "$REPO" checkout -q "$MAIN_BRANCH" @@ -1114,7 +1126,7 @@ function e2e::sync_branch() { GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ - --ref="$OTHER_BRANCH" \ + --ref="$other_branch" \ --root="$ROOT" \ --link="link" \ & @@ -1126,7 +1138,7 @@ function e2e::sync_branch() { assert_metric_eq "${METRIC_FETCH_COUNT}" 1 # Add to the branch. - git -C "$REPO" checkout -q "$OTHER_BRANCH" + git -C "$REPO" checkout -q "$other_branch" echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" git -C "$REPO" checkout -q "$MAIN_BRANCH" @@ -1138,7 +1150,7 @@ function e2e::sync_branch() { assert_metric_eq "${METRIC_FETCH_COUNT}" 2 # Move the branch backward - git -C "$REPO" checkout -q "$OTHER_BRANCH" + git -C "$REPO" checkout -q "$other_branch" git -C "$REPO" reset -q --hard HEAD^ git -C "$REPO" checkout -q "$MAIN_BRANCH" wait_for_sync "${MAXWAIT}" @@ -1168,15 +1180,15 @@ function e2e::sync_branch_switch() { assert_file_exists "$ROOT/link/file" assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1" - OTHER_BRANCH="${MAIN_BRANCH}2" - git -C "$REPO" checkout -q -b $OTHER_BRANCH + local other_branch="${MAIN_BRANCH}2" + git -C "$REPO" checkout -q -b $other_branch echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$OTHER_BRANCH" \ + --ref="$other_branch" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1188,17 +1200,17 @@ function e2e::sync_branch_switch() { # Test tag syncing ############################################## function e2e::sync_tag() { - TAG="e2e-tag" + local tag="e2e-tag" # First sync echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - git -C "$REPO" tag -f "$TAG" >/dev/null + git -C "$REPO" tag -f "$tag" >/dev/null GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ - --ref="$TAG" \ + --ref="$tag" \ --root="$ROOT" \ --link="link" \ & @@ -1212,7 +1224,7 @@ function e2e::sync_tag() { # Add something and move the tag forward echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - git -C "$REPO" tag -f "$TAG" >/dev/null + git -C "$REPO" tag -f "$tag" >/dev/null wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1222,7 +1234,7 @@ function e2e::sync_tag() { # Move the tag backward git -C "$REPO" reset -q --hard HEAD^ - git -C "$REPO" tag -f "$TAG" >/dev/null + git -C "$REPO" tag -f "$tag" >/dev/null wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1245,17 +1257,17 @@ function e2e::sync_tag() { # Test tag syncing with annotated tags ############################################## function e2e::sync_annotated_tag() { - TAG="e2e-tag" + local tag="e2e-tag" # First sync echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - git -C "$REPO" tag -af "$TAG" -m "${FUNCNAME[0]} 1" >/dev/null + git -C "$REPO" tag -af "$tag" -m "${FUNCNAME[0]} 1" >/dev/null GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ - --ref="$TAG" \ + --ref="$tag" \ --root="$ROOT" \ --link="link" \ & @@ -1269,7 +1281,7 @@ function e2e::sync_annotated_tag() { # Add something and move the tag forward echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - git -C "$REPO" tag -af "$TAG" -m "${FUNCNAME[0]} 2" >/dev/null + git -C "$REPO" tag -af "$tag" -m "${FUNCNAME[0]} 2" >/dev/null wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1279,7 +1291,7 @@ function e2e::sync_annotated_tag() { # Move the tag backward git -C "$REPO" reset -q --hard HEAD^ - git -C "$REPO" tag -af "$TAG" -m "${FUNCNAME[0]} 3" >/dev/null + git -C "$REPO" tag -af "$tag" -m "${FUNCNAME[0]} 3" >/dev/null wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1305,12 +1317,13 @@ function e2e::sync_sha() { # First sync echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - SHA=$(git -C "$REPO" rev-list -n1 HEAD) + local sha + sha=$(git -C "$REPO" rev-list -n1 HEAD) GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ - --ref="$SHA" \ + --ref="$sha" \ --root="$ROOT" \ --link="link" \ & @@ -1345,12 +1358,13 @@ function e2e::sync_sha() { # Test SHA-sync one-time ############################################## function e2e::sync_sha_once() { - SHA=$(git -C "$REPO" rev-list -n1 HEAD) + local sha + sha=$(git -C "$REPO" rev-list -n1 HEAD) GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA" \ + --ref="$sha" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1365,29 +1379,31 @@ function e2e::sync_sha_once_sync_different_sha_known() { # All revs will be known because we check out the branch echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - SHA1=$(git -C "$REPO" rev-list -n1 HEAD) + local sha1 + sha1=$(git -C "$REPO" rev-list -n1 HEAD) echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - SHA2=$(git -C "$REPO" rev-list -n1 HEAD) + local sha2 + sha2=$(git -C "$REPO" rev-list -n1 HEAD) echo "${FUNCNAME[0]} 3" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 3" - # Sync SHA1 + # Sync sha1 GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA1" \ + --ref="$sha1" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1" - # Sync SHA2 + # Sync sha2 GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA2" \ + --ref="$sha2" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1401,13 +1417,14 @@ function e2e::sync_sha_once_sync_different_sha_known() { function e2e::sync_sha_once_sync_different_sha_unknown() { echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - SHA1=$(git -C "$REPO" rev-list -n1 HEAD) + local sha1 + sha1=$(git -C "$REPO" rev-list -n1 HEAD) - # Sync SHA1 + # Sync sha1 GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA1" \ + --ref="$sha1" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1417,17 +1434,18 @@ function e2e::sync_sha_once_sync_different_sha_unknown() { # The locally synced repo does not know this new SHA. echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - SHA2=$(git -C "$REPO" rev-list -n1 HEAD) + local sha2 + sha2=$(git -C "$REPO" rev-list -n1 HEAD) # Make sure the SHA is not at HEAD, to prevent things that only work in # that case. echo "${FUNCNAME[0]} 3" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 3" - # Sync SHA2 + # Sync sha2 GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA2" \ + --ref="$sha2" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1497,27 +1515,29 @@ function e2e::sync_crash_no_worktree_cleanup_retry() { function e2e::sync_sha_shafile_exists() { echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - SHA1=$(git -C "$REPO" rev-list -n1 HEAD) + local sha1 + sha1=$(git -C "$REPO" rev-list -n1 HEAD) echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - SHA2=$(git -C "$REPO" rev-list -n1 HEAD) + local sha2 + sha2=$(git -C "$REPO" rev-list -n1 HEAD) GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA1" \ + --ref="$sha1" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]} 1" - touch "$ROOT/$SHA2" + touch "$ROOT/$sha2" GIT_SYNC \ --one-time \ --repo="file://$REPO" \ - --ref="$SHA2" \ + --ref="$sha2" \ --root="$ROOT" \ --link="link" assert_link_exists "$ROOT/link" @@ -1632,8 +1652,9 @@ function e2e::sync_on_signal_sighup() { echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" # Send signal (note --period is 100s, signal should trigger sync) - CTR=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") - docker_signal "$CTR" SIGHUP + local ctr + ctr=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") + docker_signal "$ctr" SIGHUP wait_for_sync 3 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1664,8 +1685,9 @@ function e2e::sync_on_signal_hup() { echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" # Send signal (note --period is 100s, signal should trigger sync) - CTR=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") - docker_signal "$CTR" SIGHUP + local ctr + ctr=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") + docker_signal "$ctr" SIGHUP wait_for_sync 3 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1696,8 +1718,9 @@ function e2e::sync_on_signal_1() { echo "${FUNCNAME[0]} 2" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" # Send signal (note --period is 100s, signal should trigger sync) - CTR=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") - docker_signal "$CTR" SIGHUP + local ctr + ctr=$(docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}") + docker_signal "$ctr" SIGHUP wait_for_sync 3 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -1722,6 +1745,7 @@ function e2e::sync_depth_default_shallow() { --link="link" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" + local depth depth=$(git -C "$ROOT/link" rev-list HEAD | wc -l) if [[ $depth != 1 ]]; then fail "expected depth 1, got $depth" @@ -1732,8 +1756,10 @@ function e2e::sync_depth_default_shallow() { # Test depth syncing across updates ############################################## function e2e::sync_depth_across_updates() { + local expected_depth=1 + local depth + # First sync - expected_depth="1" echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" @@ -1794,6 +1820,8 @@ function e2e::sync_depth_change_on_restart() { echo "${FUNCNAME[0]} 3" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 3" + local depth + # Sync depth=1 GIT_SYNC \ --one-time \ @@ -1860,16 +1888,18 @@ function e2e::sync_depth_change_on_restart() { ############################################## function e2e::auth_http_password() { # Run a git-over-HTTP server. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$REPO":/git/repo:ro \ e2e/test/httpd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # Try with wrong username assert_fail \ GIT_SYNC \ --one-time \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ --username="wrong" \ @@ -1880,7 +1910,7 @@ function e2e::auth_http_password() { assert_fail \ GIT_SYNC \ --one-time \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ --username="testuser" \ @@ -1890,7 +1920,7 @@ function e2e::auth_http_password() { # Try with the right password GIT_SYNC \ --one-time \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ --username="testuser" \ @@ -1906,16 +1936,18 @@ function e2e::auth_http_password() { ############################################## function e2e::auth_http_password_in_url() { # Run a git-over-HTTP server. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$REPO":/git/repo:ro \ e2e/test/httpd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # Try with wrong username assert_fail \ GIT_SYNC \ --one-time \ - --repo="http://wrong:testpass@$IP/repo" \ + --repo="http://wrong:testpass@$ip/repo" \ --root="$ROOT" \ --link="link" assert_file_absent "$ROOT/link/file" @@ -1924,7 +1956,7 @@ function e2e::auth_http_password_in_url() { assert_fail \ GIT_SYNC \ --one-time \ - --repo="http://testuser:wrong@$IP/repo" \ + --repo="http://testuser:wrong@$ip/repo" \ --root="$ROOT" \ --link="link" assert_file_absent "$ROOT/link/file" @@ -1932,7 +1964,7 @@ function e2e::auth_http_password_in_url() { # Try with the right password GIT_SYNC \ --one-time \ - --repo="http://testuser:testpass@$IP/repo" \ + --repo="http://testuser:testpass@$ip/repo" \ --root="$ROOT" \ --link="link" @@ -1946,10 +1978,12 @@ function e2e::auth_http_password_in_url() { ############################################## function e2e::auth_http_password_file() { # Run a git-over-HTTP server. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$REPO":/git/repo:ro \ e2e/test/httpd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # Make a password file with a bad password. echo -n "wrong" > "$WORK/password-file" @@ -1957,7 +1991,7 @@ function e2e::auth_http_password_file() { assert_fail \ GIT_SYNC \ --one-time \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ --username="testuser" \ @@ -1969,7 +2003,7 @@ function e2e::auth_http_password_file() { GIT_SYNC \ --one-time \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ --username="testuser" \ @@ -1985,17 +2019,19 @@ function e2e::auth_http_password_file() { ############################################## function e2e::auth_ssh() { # Run a git-over-SSH server. Use key #3 to exercise the multi-key logic. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$DOT_SSH/server/3":/dot_ssh:ro \ -v "$REPO":/git/repo:ro \ e2e/test/sshd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # Try to sync with key #1. assert_fail \ GIT_SYNC \ --one-time \ - --repo="test@$IP:/git/repo" \ + --repo="test@$ip:/git/repo" \ --root="$ROOT" \ --link="link" \ --ssh-known-hosts=false \ @@ -2005,7 +2041,7 @@ function e2e::auth_ssh() { # Try to sync with multiple keys GIT_SYNC \ --one-time \ - --repo="test@$IP:/git/repo" \ + --repo="test@$ip:/git/repo" \ --root="$ROOT" \ --link="link" \ --ssh-known-hosts=false \ @@ -2023,17 +2059,19 @@ function e2e::auth_ssh() { ############################################## function e2e::auth_ssh_url() { # Run a git-over-SSH server. Use key #3 to exercise the multi-key logic. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$DOT_SSH/server/3":/dot_ssh:ro \ -v "$REPO":/git/repo:ro \ e2e/test/sshd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # Try to sync with key #1. assert_fail \ GIT_SYNC \ --one-time \ - --repo="ssh://test@$IP/git/repo" \ + --repo="ssh://test@$ip/git/repo" \ --root="$ROOT" \ --link="link" \ --ssh-known-hosts=false \ @@ -2043,7 +2081,7 @@ function e2e::auth_ssh_url() { # Try to sync with multiple keys GIT_SYNC \ --one-time \ - --repo="ssh://test@$IP/git/repo" \ + --repo="ssh://test@$ip/git/repo" \ --root="$ROOT" \ --link="link" \ --ssh-known-hosts=false \ @@ -2061,10 +2099,11 @@ function e2e::auth_ssh_url() { ############################################## function e2e::auth_askpass_url_wrong_password() { # run the askpass_url service with wrong password - HITLOG="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + local hitlog="$WORK/hitlog" + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 200 OK" @@ -2072,7 +2111,8 @@ function e2e::auth_askpass_url_wrong_password() { echo "username=my-username" echo "password=wrong" ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") assert_fail \ GIT_SYNC \ @@ -2081,7 +2121,7 @@ function e2e::auth_askpass_url_wrong_password() { --root="$ROOT" \ --link="link" \ --git="/$ASKPASS_GIT" \ - --askpass-url="http://$IP/git_askpass" + --askpass-url="http://$ip/git_askpass" assert_file_absent "$ROOT/link/file" } @@ -2090,10 +2130,11 @@ function e2e::auth_askpass_url_wrong_password() { ############################################## function e2e::auth_askpass_url_correct_password() { # run with askpass_url service with correct password - HITLOG="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + local hitlog="$WORK/hitlog" + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 200 OK" @@ -2101,7 +2142,8 @@ function e2e::auth_askpass_url_correct_password() { echo "username=my-username" echo "password=my-password" ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --one-time \ @@ -2109,7 +2151,7 @@ function e2e::auth_askpass_url_correct_password() { --root="$ROOT" \ --link="link" \ --git="/$ASKPASS_GIT" \ - --askpass-url="http://$IP/git_askpass" + --askpass-url="http://$ip/git_askpass" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" @@ -2121,10 +2163,11 @@ function e2e::auth_askpass_url_correct_password() { ############################################## function e2e::auth_askpass_url_sometimes_wrong() { # run with askpass_url service which alternates good/bad replies. - HITLOG="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + local hitlog="$WORK/hitlog" + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 200 OK" @@ -2139,7 +2182,8 @@ function e2e::auth_askpass_url_sometimes_wrong() { touch /tmp/flag fi ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # First sync echo "${FUNCNAME[0]} 1" > "$REPO/file" @@ -2151,7 +2195,7 @@ function e2e::auth_askpass_url_sometimes_wrong() { --root="$ROOT" \ --link="link" \ --git="/$ASKPASS_GIT" \ - --askpass-url="http://$IP/git_askpass" \ + --askpass-url="http://$ip/git_askpass" \ --max-failures=2 \ & wait_for_sync "${MAXWAIT}" @@ -2180,10 +2224,11 @@ function e2e::auth_askpass_url_sometimes_wrong() { ############################################## function e2e::auth_askpass_url_flaky() { # run with askpass_url service which alternates good/bad replies. - HITLOG="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + local hitlog="$WORK/hitlog" + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X if [ -f /tmp/flag ]; then @@ -2198,7 +2243,8 @@ function e2e::auth_askpass_url_flaky() { touch /tmp/flag fi ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") # First sync echo "${FUNCNAME[0]} 1" > "$REPO/file" @@ -2210,7 +2256,7 @@ function e2e::auth_askpass_url_flaky() { --root="$ROOT" \ --link="link" \ --git="/$ASKPASS_GIT" \ - --askpass-url="http://$IP/git_askpass" \ + --askpass-url="http://$ip/git_askpass" \ --max-failures=2 \ & wait_for_sync "${MAXWAIT}" @@ -2239,10 +2285,11 @@ function e2e::auth_askpass_url_flaky() { ############################################## function e2e::auth_askpass_url_slow_start() { # run with askpass_url service which takes a while to come up - HITLOG="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + local hitlog="$WORK/hitlog" + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ --entrypoint sh \ e2e/test/ncsvr \ -c "sleep 4; @@ -2252,7 +2299,8 @@ function e2e::auth_askpass_url_slow_start() { echo \"username=my-username\" echo \"password=my-password\" '") - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=1s \ @@ -2260,7 +2308,7 @@ function e2e::auth_askpass_url_slow_start() { --root="$ROOT" \ --link="link" \ --git="/$ASKPASS_GIT" \ - --askpass-url="http://$IP/git_askpass" \ + --askpass-url="http://$ip/git_askpass" \ --max-failures=5 \ & sleep 1 @@ -2443,18 +2491,20 @@ function e2e::exechook_startup_after_crash() { # Test webhook success ############################################## function e2e::webhook_success() { - HITLOG="$WORK/hitlog" + local hitlog="$WORK/hitlog" # First sync - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 200 OK" echo ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") echo "${FUNCNAME[0]} 1" > "$REPO/file" git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" @@ -2462,7 +2512,7 @@ function e2e::webhook_success() { --period=100ms \ --repo="file://$REPO" \ --root="$ROOT" \ - --webhook-url="http://$IP" \ + --webhook-url="http://$ip" \ --webhook-success-status=200 \ --link="link" \ & @@ -2470,7 +2520,7 @@ function e2e::webhook_success() { # check that basic call works wait_for_sync "${MAXWAIT}" sleep 1 # webhooks are async - assert_file_lines_eq "$HITLOG" 1 + assert_file_lines_eq "$hitlog" 1 # Move forward echo "${FUNCNAME[0]} 2" > "$REPO/file" @@ -2479,38 +2529,40 @@ function e2e::webhook_success() { # check that another call works wait_for_sync "${MAXWAIT}" sleep 1 # webhooks are async - assert_file_lines_eq "$HITLOG" 2 + assert_file_lines_eq "$hitlog" 2 } ############################################## # Test webhook fail-retry ############################################## function e2e::webhook_fail_retry() { - HITLOG="$WORK/hitlog" - SCRIPT="$WORK/http_resp.sh" - touch "$SCRIPT" - chmod 755 "$SCRIPT" + local hitlog="$WORK/hitlog" + local script="$WORK/http_resp.sh" + touch "$script" + chmod 755 "$script" # First sync - return a failure to ensure that we try again - cat /dev/null > "$HITLOG" - cat > "$SCRIPT" << __EOF__ + cat /dev/null > "$hitlog" + cat > "$script" << __EOF__ #!/bin/sh read X echo "HTTP/1.1 500 Internal Server Error" echo __EOF__ - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ - -v "$SCRIPT":/http_resp.sh \ + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ + -v "$script":/http_resp.sh \ e2e/test/ncsvr \ 80 '/http_resp.sh') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ --root="$ROOT" \ - --webhook-url="http://$IP" \ + --webhook-url="http://$ip" \ --webhook-success-status=200 \ --link="link" \ & @@ -2518,66 +2570,70 @@ __EOF__ # Check that webhook was called wait_for_sync "${MAXWAIT}" sleep 1 # webhooks are async - assert_file_lines_ge "$HITLOG" 1 + assert_file_lines_ge "$hitlog" 1 # Now return 200, ensure that it gets called - cat /dev/null > "$HITLOG" - cat > "$SCRIPT" << __EOF__ + cat /dev/null > "$hitlog" + cat > "$script" << __EOF__ #!/bin/sh read X echo "HTTP/1.1 200 OK" echo __EOF__ sleep 2 # webhooks are async - assert_file_lines_eq "$HITLOG" 1 + assert_file_lines_eq "$hitlog" 1 } ############################################## # Test webhook success with --one-time ############################################## function e2e::webhook_success_once() { - HITLOG="$WORK/hitlog" + local hitlog="$WORK/hitlog" # First sync - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 200 OK" echo ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=100ms \ --one-time \ --repo="file://$REPO" \ --root="$ROOT" \ - --webhook-url="http://$IP" \ + --webhook-url="http://$ip" \ --webhook-success-status=200 \ --link="link" # check that basic call works - assert_file_lines_eq "$HITLOG" 1 + assert_file_lines_eq "$hitlog" 1 } ############################################## # Test webhook fail with --one-time ############################################## function e2e::webhook_fail_retry_once() { - HITLOG="$WORK/hitlog" + local hitlog="$WORK/hitlog" # First sync - return a failure to ensure that we try again - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 500 Internal Server Error" echo ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") assert_fail \ GIT_SYNC \ @@ -2585,37 +2641,39 @@ function e2e::webhook_fail_retry_once() { --one-time \ --repo="file://$REPO" \ --root="$ROOT" \ - --webhook-url="http://$IP" \ + --webhook-url="http://$ip" \ --webhook-success-status=200 \ --link="link" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" assert_file_eq "$ROOT/link/file" "${FUNCNAME[0]}" - assert_file_lines_eq "$HITLOG" 1 + assert_file_lines_eq "$hitlog" 1 } ############################################## # Test webhook fire-and-forget ############################################## function e2e::webhook_fire_and_forget() { - HITLOG="$WORK/hitlog" + local hitlog="$WORK/hitlog" - cat /dev/null > "$HITLOG" - CTR=$(docker_run \ - -v "$HITLOG":/var/log/hits \ + cat /dev/null > "$hitlog" + local ctr + ctr=$(docker_run \ + -v "$hitlog":/var/log/hits \ e2e/test/ncsvr \ 80 'read X echo "HTTP/1.1 404 Not Found" echo ') - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=100ms \ --repo="file://$REPO" \ --root="$ROOT" \ - --webhook-url="http://$IP" \ + --webhook-url="http://$ip" \ --webhook-success-status=0 \ --link="link" \ & @@ -2623,7 +2681,7 @@ function e2e::webhook_fire_and_forget() { # check that basic call works wait_for_sync "${MAXWAIT}" sleep 1 # webhooks are async - assert_file_lines_eq "$HITLOG" 1 + assert_file_lines_eq "$hitlog" 1 } ############################################## @@ -2718,27 +2776,27 @@ function e2e::expose_http_after_restart() { ############################################## function e2e::submodule_sync_default() { # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule.file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule.file" # Init nested submodule repo - NESTED_SUBMODULE_REPO_NAME="nested-sub" - NESTED_SUBMODULE="$WORK/$NESTED_SUBMODULE_REPO_NAME" - mkdir "$NESTED_SUBMODULE" + local nested_submodule_repo_name="nested-sub" + local nested_submodule="$WORK/$nested_submodule_repo_name" + mkdir "$nested_submodule" - git -C "$NESTED_SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "nested-submodule" > "$NESTED_SUBMODULE/nested-submodule.file" - git -C "$NESTED_SUBMODULE" add nested-submodule.file - git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule.file" + git -C "$nested_submodule" init -q -b "$MAIN_BRANCH" + echo "nested-submodule" > "$nested_submodule/nested-submodule.file" + git -C "$nested_submodule" add nested-submodule.file + git -C "$nested_submodule" commit -aqm "init nested-submodule.file" # Add submodule - git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$SUBMODULE "$SUBMODULE_REPO_NAME" + git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$submodule "$submodule_repo_name" git -C "$REPO" commit -aqm "add submodule" GIT_SYNC \ @@ -2750,73 +2808,73 @@ function e2e::submodule_sync_default() { wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "submodule" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "submodule" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1 # Make change in submodule repo - echo "${FUNCNAME[0]} 2" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" commit -qam "${FUNCNAME[0]} 2" + echo "${FUNCNAME[0]} 2" > "$submodule/submodule.file" + git -C "$submodule" commit -qam "${FUNCNAME[0]} 2" git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "${FUNCNAME[0]} 2" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "${FUNCNAME[0]} 2" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 2 # Move backward in submodule repo - git -C "$SUBMODULE" reset -q --hard HEAD^ + git -C "$submodule" reset -q --hard HEAD^ git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 3" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "submodule" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "submodule" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 3 # Add nested submodule to submodule repo - git -C "$SUBMODULE" -c protocol.file.allow=always submodule add -q file://$NESTED_SUBMODULE "$NESTED_SUBMODULE_REPO_NAME" - git -C "$SUBMODULE" commit -aqm "add nested submodule" + git -C "$submodule" -c protocol.file.allow=always submodule add -q file://$nested_submodule "$nested_submodule_repo_name" + git -C "$submodule" commit -aqm "add nested submodule" git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 4" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" "nested-submodule" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" "nested-submodule" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 4 # Remove nested submodule - git -C "$SUBMODULE" submodule deinit -q $NESTED_SUBMODULE_REPO_NAME - rm -rf "$SUBMODULE/.git/modules/$NESTED_SUBMODULE_REPO_NAME" - git -C "$SUBMODULE" rm -qf $NESTED_SUBMODULE_REPO_NAME - git -C "$SUBMODULE" commit -aqm "delete nested submodule" + git -C "$submodule" submodule deinit -q $nested_submodule_repo_name + rm -rf "$submodule/.git/modules/$nested_submodule_repo_name" + git -C "$submodule" rm -qf $nested_submodule_repo_name + git -C "$submodule" commit -aqm "delete nested submodule" git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 5" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_absent "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_absent "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 5 # Remove submodule - git -C "$REPO" submodule deinit -q $SUBMODULE_REPO_NAME - rm -rf "$REPO/.git/modules/$SUBMODULE_REPO_NAME" - git -C "$REPO" rm -qf $SUBMODULE_REPO_NAME + git -C "$REPO" submodule deinit -q $submodule_repo_name + rm -rf "$REPO/.git/modules/$submodule_repo_name" + git -C "$REPO" rm -qf $submodule_repo_name git -C "$REPO" commit -aqm "delete submodule" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_absent "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" + assert_file_absent "$ROOT/link/$submodule_repo_name/submodule.file" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 6 - rm -rf $SUBMODULE - rm -rf $NESTED_SUBMODULE + rm -rf $submodule + rm -rf $nested_submodule } ############################################## @@ -2824,19 +2882,22 @@ function e2e::submodule_sync_default() { ############################################## function e2e::submodule_sync_depth() { # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" + + git -C "$submodule" init -q -b "$MAIN_BRANCH" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" + local expected_depth="1" + local depth + local submodule_depth # First sync - expected_depth="1" - echo "${FUNCNAME[0]} 1" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "submodule ${FUNCNAME[0]} 1" - git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$SUBMODULE "$SUBMODULE_REPO_NAME" - git -C "$REPO" config -f "$REPO/.gitmodules" "submodule.$SUBMODULE_REPO_NAME.shallow" true + echo "${FUNCNAME[0]} 1" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "submodule ${FUNCNAME[0]} 1" + git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$submodule "$submodule_repo_name" + git -C "$REPO" config -f "$REPO/.gitmodules" "submodule.$submodule_repo_name.shallow" true git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" GIT_SYNC \ @@ -2848,55 +2909,55 @@ function e2e::submodule_sync_depth() { & wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "${FUNCNAME[0]} 1" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "${FUNCNAME[0]} 1" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1 depth=$(git -C "$ROOT/link" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$depth" ]]; then fail "initial depth mismatch expected=$expected_depth actual=$depth" fi - submodule_depth=$(git -C "$ROOT/link/$SUBMODULE_REPO_NAME" rev-list HEAD | wc -l) + submodule_depth=$(git -C "$ROOT/link/$submodule_repo_name" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$submodule_depth" ]]; then fail "initial submodule depth mismatch expected=$expected_depth actual=$submodule_depth" fi # Move forward - echo "${FUNCNAME[0]} 2" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" commit -aqm "submodule ${FUNCNAME[0]} 2" + echo "${FUNCNAME[0]} 2" > "$submodule/submodule.file" + git -C "$submodule" commit -aqm "submodule ${FUNCNAME[0]} 2" git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "${FUNCNAME[0]} 2" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "${FUNCNAME[0]} 2" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 2 depth=$(git -C "$ROOT/link" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$depth" ]]; then fail "forward depth mismatch expected=$expected_depth actual=$depth" fi - submodule_depth=$(git -C "$ROOT/link/$SUBMODULE_REPO_NAME" rev-list HEAD | wc -l) + submodule_depth=$(git -C "$ROOT/link/$submodule_repo_name" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$submodule_depth" ]]; then fail "forward submodule depth mismatch expected=$expected_depth actual=$submodule_depth" fi # Move backward - git -C "$SUBMODULE" reset -q --hard HEAD^ + git -C "$submodule" reset -q --hard HEAD^ git -C "$REPO" -c protocol.file.allow=always submodule update --recursive --remote > /dev/null 2>&1 git -C "$REPO" commit -qam "${FUNCNAME[0]} 3" wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "${FUNCNAME[0]} 1" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "${FUNCNAME[0]} 1" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 3 depth=$(git -C "$ROOT/link" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$depth" ]]; then fail "initial depth mismatch expected=$expected_depth actual=$depth" fi - submodule_depth=$(git -C "$ROOT/link/$SUBMODULE_REPO_NAME" rev-list HEAD | wc -l) + submodule_depth=$(git -C "$ROOT/link/$submodule_repo_name" rev-list HEAD | wc -l) if [[ "$expected_depth" != "$submodule_depth" ]]; then fail "initial submodule depth mismatch expected=$expected_depth actual=$submodule_depth" fi - rm -rf $SUBMODULE + rm -rf $submodule } ############################################## @@ -2904,17 +2965,17 @@ function e2e::submodule_sync_depth() { ############################################## function e2e::submodule_sync_off() { # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule file" # Add submodule - git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$SUBMODULE + git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$submodule git -C "$REPO" commit -aqm "add submodule" GIT_SYNC \ @@ -2925,8 +2986,8 @@ function e2e::submodule_sync_off() { --submodules=off \ & wait_for_sync "${MAXWAIT}" - assert_file_absent "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - rm -rf $SUBMODULE + assert_file_absent "$ROOT/link/$submodule_repo_name/submodule.file" + rm -rf $submodule } ############################################## @@ -2934,29 +2995,29 @@ function e2e::submodule_sync_off() { ############################################## function e2e::submodule_sync_shallow() { # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule file" # Init nested submodule repo - NESTED_SUBMODULE_REPO_NAME="nested-sub" - NESTED_SUBMODULE="$WORK/$NESTED_SUBMODULE_REPO_NAME" - mkdir "$NESTED_SUBMODULE" + local nested_submodule_repo_name="nested-sub" + local nested_submodule="$WORK/$nested_submodule_repo_name" + mkdir "$nested_submodule" - git -C "$NESTED_SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "nested-submodule" > "$NESTED_SUBMODULE/nested-submodule.file" - git -C "$NESTED_SUBMODULE" add nested-submodule.file - git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule file" - git -C "$SUBMODULE" -c protocol.file.allow=always submodule add -q file://$NESTED_SUBMODULE "$NESTED_SUBMODULE_REPO_NAME" - git -C "$SUBMODULE" commit -aqm "add nested submodule" + git -C "$nested_submodule" init -q -b "$MAIN_BRANCH" + echo "nested-submodule" > "$nested_submodule/nested-submodule.file" + git -C "$nested_submodule" add nested-submodule.file + git -C "$nested_submodule" commit -aqm "init nested-submodule file" + git -C "$submodule" -c protocol.file.allow=always submodule add -q file://$nested_submodule "$nested_submodule_repo_name" + git -C "$submodule" commit -aqm "add nested submodule" # Add submodule - git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$SUBMODULE "$SUBMODULE_REPO_NAME" + git -C "$REPO" -c protocol.file.allow=always submodule add -q file://$submodule "$submodule_repo_name" git -C "$REPO" commit -aqm "add submodule" GIT_SYNC \ @@ -2969,10 +3030,10 @@ function e2e::submodule_sync_shallow() { wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_absent "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" - rm -rf $SUBMODULE - rm -rf $NESTED_SUBMODULE + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_absent "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" + rm -rf $submodule + rm -rf $nested_submodule } ############################################## @@ -2980,18 +3041,19 @@ function e2e::submodule_sync_shallow() { ############################################## function e2e::submodule_sync_relative() { # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule file" # Add submodule - REL="$(realpath --relative-to "$REPO" "$WORK/$SUBMODULE_REPO_NAME")" - git -C "$REPO" -c protocol.file.allow=always submodule add -q "$REL" "$SUBMODULE_REPO_NAME" + local rel + rel="$(realpath --relative-to "$REPO" "$WORK/$submodule_repo_name")" + git -C "$REPO" -c protocol.file.allow=always submodule add -q "$rel" "$submodule_repo_name" git -C "$REPO" commit -aqm "add submodule" GIT_SYNC \ @@ -3003,11 +3065,11 @@ function e2e::submodule_sync_relative() { wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_eq "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" "submodule" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_eq "$ROOT/link/$submodule_repo_name/submodule.file" "submodule" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1 - rm -rf $SUBMODULE + rm -rf $submodule } ############################################## @@ -3015,61 +3077,67 @@ function e2e::submodule_sync_relative() { ############################################## function e2e::submodule_sync_over_ssh_different_keys() { # Init nested submodule repo - NESTED_SUBMODULE_REPO_NAME="nested-sub" - NESTED_SUBMODULE="$WORK/$NESTED_SUBMODULE_REPO_NAME" - mkdir "$NESTED_SUBMODULE" + local nested_submodule_repo_name="nested-sub" + local nested_submodule="$WORK/$nested_submodule_repo_name" + mkdir "$nested_submodule" - git -C "$NESTED_SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "nested-submodule" > "$NESTED_SUBMODULE/nested-submodule.file" - git -C "$NESTED_SUBMODULE" add nested-submodule.file - git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule.file" + git -C "$nested_submodule" init -q -b "$MAIN_BRANCH" + echo "nested-submodule" > "$nested_submodule/nested-submodule.file" + git -C "$nested_submodule" add nested-submodule.file + git -C "$nested_submodule" commit -aqm "init nested-submodule.file" # Run a git-over-SSH server. Use key #1. - CTR_SUBSUB=$(docker_run \ + local ctr_subsub + ctr_subsub=$(docker_run \ -v "$DOT_SSH/server/1":/dot_ssh:ro \ - -v "$NESTED_SUBMODULE":/git/repo:ro \ + -v "$nested_submodule":/git/repo:ro \ e2e/test/sshd) - IP_SUBSUB=$(docker_ip "$CTR_SUBSUB") + local ip_subsub + ip_subsub=$(docker_ip "$ctr_subsub") # Tell local git not to do host checking and to use the test keys. export GIT_SSH_COMMAND="ssh -F none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i $DOT_SSH/1/id_local -i $DOT_SSH/2/id_local" # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule.file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule.file" # Add nested submodule to submodule repo - git -C "$SUBMODULE" submodule add -q "test@$IP_SUBSUB:/git/repo" "$NESTED_SUBMODULE_REPO_NAME" - git -C "$SUBMODULE" commit -aqm "add nested submodule" + git -C "$submodule" submodule add -q "test@$ip_subsub:/git/repo" "$nested_submodule_repo_name" + git -C "$submodule" commit -aqm "add nested submodule" # Run a git-over-SSH server. Use key #2. - CTR_SUB=$(docker_run \ + local ctr_sub + ctr_sub=$(docker_run \ -v "$DOT_SSH/server/2":/dot_ssh:ro \ - -v "$SUBMODULE":/git/repo:ro \ + -v "$submodule":/git/repo:ro \ e2e/test/sshd) - IP_SUB=$(docker_ip "$CTR_SUB") + local ip_sub + ip_sub=$(docker_ip "$ctr_sub") # Add the submodule to the main repo - git -C "$REPO" submodule add -q "test@$IP_SUB:/git/repo" "$SUBMODULE_REPO_NAME" + git -C "$REPO" submodule add -q "test@$ip_sub:/git/repo" "$submodule_repo_name" git -C "$REPO" commit -aqm "add submodule" git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 # Run a git-over-SSH server. Use key #3. - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$DOT_SSH/server/3":/dot_ssh:ro \ -v "$REPO":/git/repo:ro \ e2e/test/sshd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=100ms \ - --repo="test@$IP:/git/repo" \ + --repo="test@$ip:/git/repo" \ --root="$ROOT" \ --link="link" \ --ssh-key-file="/ssh/secret.1" \ @@ -3080,12 +3148,12 @@ function e2e::submodule_sync_over_ssh_different_keys() { wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1 - rm -rf $SUBMODULE - rm -rf $NESTED_SUBMODULE + rm -rf $submodule + rm -rf $nested_submodule } ############################################## @@ -3093,81 +3161,87 @@ function e2e::submodule_sync_over_ssh_different_keys() { ############################################## function e2e::submodule_sync_over_http_different_passwords() { # Init nested submodule repo - NESTED_SUBMODULE_REPO_NAME="nested-sub" - NESTED_SUBMODULE="$WORK/$NESTED_SUBMODULE_REPO_NAME" - mkdir "$NESTED_SUBMODULE" + local nested_submodule_repo_name="nested-sub" + local nested_submodule="$WORK/$nested_submodule_repo_name" + mkdir "$nested_submodule" - git -C "$NESTED_SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "nested-submodule" > "$NESTED_SUBMODULE/nested-submodule.file" - git -C "$NESTED_SUBMODULE" add nested-submodule.file - git -C "$NESTED_SUBMODULE" commit -aqm "init nested-submodule.file" + git -C "$nested_submodule" init -q -b "$MAIN_BRANCH" + echo "nested-submodule" > "$nested_submodule/nested-submodule.file" + git -C "$nested_submodule" add nested-submodule.file + git -C "$nested_submodule" commit -aqm "init nested-submodule.file" # Run a git-over-SSH server. Use password "test1". # shellcheck disable=SC2016 echo 'test:$apr1$cXiFWR90$Pmoz7T8kEmlpC9Bpj4MX3.' > "$WORK/htpasswd.1" - CTR_SUBSUB=$(docker_run \ - -v "$NESTED_SUBMODULE":/git/repo:ro \ + local ctr_subsub + ctr_subsub=$(docker_run \ + -v "$nested_submodule":/git/repo:ro \ -v "$WORK/htpasswd.1":/etc/htpasswd:ro \ e2e/test/httpd) - IP_SUBSUB=$(docker_ip "$CTR_SUBSUB") + local ip_subsub + ip_subsub=$(docker_ip "$ctr_subsub") # Init submodule repo - SUBMODULE_REPO_NAME="sub" - SUBMODULE="$WORK/$SUBMODULE_REPO_NAME" - mkdir "$SUBMODULE" + local submodule_repo_name="sub" + local submodule="$WORK/$submodule_repo_name" + mkdir "$submodule" - git -C "$SUBMODULE" init -q -b "$MAIN_BRANCH" - echo "submodule" > "$SUBMODULE/submodule.file" - git -C "$SUBMODULE" add submodule.file - git -C "$SUBMODULE" commit -aqm "init submodule.file" + git -C "$submodule" init -q -b "$MAIN_BRANCH" + echo "submodule" > "$submodule/submodule.file" + git -C "$submodule" add submodule.file + git -C "$submodule" commit -aqm "init submodule.file" # Add nested submodule to submodule repo - echo -ne "url=http://$IP_SUBSUB/repo\nusername=test\npassword=test1\n" | git credential approve - git -C "$SUBMODULE" submodule add -q "http://$IP_SUBSUB/repo" "$NESTED_SUBMODULE_REPO_NAME" - git -C "$SUBMODULE" commit -aqm "add nested submodule" + echo -ne "url=http://$ip_subsub/repo\nusername=test\npassword=test1\n" | git credential approve + git -C "$submodule" submodule add -q "http://$ip_subsub/repo" "$nested_submodule_repo_name" + git -C "$submodule" commit -aqm "add nested submodule" # Run a git-over-SSH server. Use password "test2". # shellcheck disable=SC2016 echo 'test:$apr1$vWBoWUBS$2H.WFxF8T7rH/gZF99Edl/' > "$WORK/htpasswd.2" - CTR_SUB=$(docker_run \ - -v "$SUBMODULE":/git/repo:ro \ + local ctr_sub + ctr_sub=$(docker_run \ + -v "$submodule":/git/repo:ro \ -v "$WORK/htpasswd.2":/etc/htpasswd:ro \ e2e/test/httpd) - IP_SUB=$(docker_ip "$CTR_SUB") + local ip_sub + ip_sub=$(docker_ip "$ctr_sub") # Add the submodule to the main repo - echo -ne "url=http://$IP_SUB/repo\nusername=test\npassword=test2\n" | git credential approve - git -C "$REPO" submodule add -q "http://$IP_SUB/repo" "$SUBMODULE_REPO_NAME" + echo -ne "url=http://$ip_sub/repo\nusername=test\npassword=test2\n" | git credential approve + git -C "$REPO" submodule add -q "http://$ip_sub/repo" "$submodule_repo_name" git -C "$REPO" commit -aqm "add submodule" git -C "$REPO" submodule update --recursive --remote > /dev/null 2>&1 # Run a git-over-SSH server. Use password "test3". # shellcheck disable=SC2016 echo 'test:$apr1$oKP2oGwp$ESJ4FESEP/8Sisy02B/vM/' > "$WORK/htpasswd.3" - CTR=$(docker_run \ + local ctr + ctr=$(docker_run \ -v "$REPO":/git/repo:ro \ -v "$WORK/htpasswd.3":/etc/htpasswd:ro \ e2e/test/httpd) - IP=$(docker_ip "$CTR") + local ip + ip=$(docker_ip "$ctr") GIT_SYNC \ --period=100ms \ - --repo="http://$IP/repo" \ + --repo="http://$ip/repo" \ --root="$ROOT" \ --link="link" \ - --credential="{ \"url\": \"http://$IP_SUBSUB/repo\", \"username\": \"test\", \"password\": \"test1\" }" \ - --credential="{ \"url\": \"http://$IP_SUB/repo\", \"username\": \"test\", \"password\": \"test2\" }" \ - --credential="{ \"url\": \"http://$IP/repo\", \"username\": \"test\", \"password\": \"test3\" }" \ + --credential="{ \"url\": \"http://$ip_subsub/repo\", \"username\": \"test\", \"password\": \"test1\" }" \ + --credential="{ \"url\": \"http://$ip_sub/repo\", \"username\": \"test\", \"password\": \"test2\" }" \ + --credential="{ \"url\": \"http://$ip/repo\", \"username\": \"test\", \"password\": \"test3\" }" \ & wait_for_sync "${MAXWAIT}" assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/submodule.file" - assert_file_exists "$ROOT/link/$SUBMODULE_REPO_NAME/$NESTED_SUBMODULE_REPO_NAME/nested-submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/submodule.file" + assert_file_exists "$ROOT/link/$submodule_repo_name/$nested_submodule_repo_name/nested-submodule.file" assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1 - rm -rf $SUBMODULE - rm -rf $NESTED_SUBMODULE + rm -rf $submodule + rm -rf $nested_submodule } ############################################## @@ -3382,32 +3456,36 @@ function e2e::github_https() { # Test git-gc default ############################################## function e2e::gc_default() { - SHA1=$(git -C "$REPO" rev-parse HEAD) + local sha1 + sha1=$(git -C "$REPO" rev-parse HEAD) dd if=/dev/urandom of="$REPO/big1" bs=1024 count=4096 >/dev/null git -C "$REPO" add . git -C "$REPO" commit -qam "${FUNCNAME[0]} 1" - SHA2=$(git -C "$REPO" rev-parse HEAD) + local sha2 + sha2=$(git -C "$REPO" rev-parse HEAD) dd if=/dev/urandom of="$REPO/big2" bs=1024 count=4096 >/dev/null git -C "$REPO" add . git -C "$REPO" commit -qam "${FUNCNAME[0]} 2" - SHA3=$(git -C "$REPO" rev-parse HEAD) + local sha3 + sha3=$(git -C "$REPO" rev-parse HEAD) GIT_SYNC \ --one-time \ --repo="file://$REPO" \ --root="$ROOT" \ --link="link" \ - --ref="$SHA3" \ + --ref="$sha3" \ --depth=0 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/big1" assert_file_exists "$ROOT/link/big2" - SIZE=$(du -s "$ROOT" | cut -f1) - if [ "$SIZE" -lt 14000 ]; then - fail "repo is impossibly small: $SIZE" + local size + size=$(du -s "$ROOT" | cut -f1) + if [ "$size" -lt 14000 ]; then + fail "repo is impossibly small: $size" fi - if [ "$SIZE" -gt 18000 ]; then - fail "repo is too big: $SIZE" + if [ "$size" -gt 18000 ]; then + fail "repo is too big: $size" fi GIT_SYNC \ @@ -3415,17 +3493,17 @@ function e2e::gc_default() { --repo="file://$REPO" \ --root="$ROOT" \ --link="link" \ - --ref="$SHA3" \ + --ref="$sha3" \ --depth=1 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/big1" assert_file_exists "$ROOT/link/big2" - SIZE=$(du -s "$ROOT" | cut -f1) - if [ "$SIZE" -lt 14000 ]; then - fail "repo is impossibly small: $SIZE" + size=$(du -s "$ROOT" | cut -f1) + if [ "$size" -lt 14000 ]; then + fail "repo is impossibly small: $size" fi - if [ "$SIZE" -gt 18000 ]; then - fail "repo is too big: $SIZE" + if [ "$size" -gt 18000 ]; then + fail "repo is too big: $size" fi GIT_SYNC \ @@ -3433,17 +3511,17 @@ function e2e::gc_default() { --repo="file://$REPO" \ --root="$ROOT" \ --link="link" \ - --ref="$SHA2" \ + --ref="$sha2" \ --depth=1 assert_link_exists "$ROOT/link" assert_file_exists "$ROOT/link/big1" assert_file_absent "$ROOT/link/big2" - SIZE=$(du -s "$ROOT" | cut -f1) - if [ "$SIZE" -lt 7000 ]; then - fail "repo is impossibly small: $SIZE" + size=$(du -s "$ROOT" | cut -f1) + if [ "$size" -lt 7000 ]; then + fail "repo is impossibly small: $size" fi - if [ "$SIZE" -gt 9000 ]; then - fail "repo is too big: $SIZE" + if [ "$size" -gt 9000 ]; then + fail "repo is too big: $size" fi GIT_SYNC \ @@ -3451,17 +3529,17 @@ function e2e::gc_default() { --repo="file://$REPO" \ --root="$ROOT" \ --link="link" \ - --ref="$SHA1" \ + --ref="$sha1" \ --depth=1 assert_link_exists "$ROOT/link" assert_file_absent "$ROOT/link/big1" assert_file_absent "$ROOT/link/big2" - SIZE=$(du -s "$ROOT" | cut -f1) - if [ "$SIZE" -lt 100 ]; then - fail "repo is impossibly small: $SIZE" + size=$(du -s "$ROOT" | cut -f1) + if [ "$size" -lt 100 ]; then + fail "repo is impossibly small: $size" fi - if [ "$SIZE" -gt 1000 ]; then - fail "repo is too big: $SIZE" + if [ "$size" -gt 1000 ]; then + fail "repo is too big: $size" fi } @@ -3597,14 +3675,14 @@ $build_container && make container REGISTRY=e2e VERSION="${E2E_TAG}" ALLOW_STALE make test-tools REGISTRY=e2e function finish() { - r=$? + local ret=$? trap "" INT EXIT ERR - if [[ $r != 0 ]]; then + if [[ $ret != 0 ]]; then echo echo "the directory $DIR was not removed as it contains"\ "log files useful for debugging" fi - exit $r + exit $ret } trap finish INT EXIT ERR @@ -3619,7 +3697,7 @@ trap finish INT EXIT ERR # $1: the name of a variable to populate with the return code # $2+: the test function to run and optional args function run_test() { - retvar=$1 + local retvar=$1 shift declare -g "$retvar" @@ -3661,8 +3739,8 @@ if [[ -n "${VERBOSE:-}" ]]; then echo fi -FAILS=() -FINAL_RET=0 +failures=() +final_ret=0 RUNS="${RUNS:-1}" echo @@ -3680,17 +3758,17 @@ echo # Iterate over the chosen tests and run them. for t; do - TEST_FN="e2e::${t}" - TEST_RET=0 - RUN=0 - while (( "${RUN}" < "${RUNS}" )); do + test_fn="e2e::${t}" + test_ret=0 + run=0 + while (( "${run}" < "${RUNS}" )); do clean_root clean_work - init_repo "${TEST_FN}" + init_repo "${test_fn}" sfx="" if (( "${RUNS}" > 1 )); then - sfx=" ($((RUN+1))/${RUNS})" + sfx=" ($((run+1))/${RUNS})" fi echo -n "testcase ${t}${sfx}: " @@ -3698,38 +3776,38 @@ for t; do exec 3>&1 # See comments on run_test for details. - RUN_RET=0 - LOG="${DIR}/log.$t" - run_test RUN_RET "${TEST_FN}" >"${LOG}.${RUN}" 2>&1 - if [[ "$RUN_RET" == 0 ]]; then + run_ret=0 + log="${DIR}/log.$t" + run_test run_ret "${test_fn}" >"${log}.${run}" 2>&1 + if [[ "$run_ret" == 0 ]]; then pass - elif [[ "$RUN_RET" == 43 ]]; then + elif [[ "$run_ret" == 43 ]]; then true # do nothing else - TEST_RET=1 - if [[ "$RUN_RET" != 42 ]]; then + test_ret=1 + if [[ "$run_ret" != 42 ]]; then echo "FAIL: unknown error" fi if [[ -n "${VERBOSE:-}" ]]; then echo -ne "\n\n" - echo "LOG ----------------------" - cat "${LOG}.${RUN}" + echo "log ----------------------" + cat "${log}.${run}" echo "--------------------------" echo -ne "\n\n" fi fi remove_containers || true - RUN=$((RUN+1)) + run=$((run+1)) done - if [[ "$TEST_RET" != 0 ]]; then - FINAL_RET=1 - FAILS+=("$t (log: ${LOG}.*)") + if [[ "$test_ret" != 0 ]]; then + final_ret=1 + failures+=("$t (log: ${log}.*)") fi done -if [[ "$FINAL_RET" != 0 ]]; then +if [[ "$final_ret" != 0 ]]; then echo echo "the following tests failed:" - for f in "${FAILS[@]}"; do + for f in "${failures[@]}"; do echo " $f" done exit 1 From bd88a3f9b0c05a9048b356e76c95a3f4261f061d Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 1 May 2025 17:24:12 -0700 Subject: [PATCH 2/2] Fix whitespace --- test_e2e.sh | 101 ++++++++++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/test_e2e.sh b/test_e2e.sh index e8be4274d..a65f381fa 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -20,20 +20,19 @@ set -o pipefail # shellcheck disable=SC2120 function caller() { - local stack_skip=${1:-0} - stack_skip=$((stack_skip + 1)) - if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then - local i - for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++)) - do - local frame_no=$((i - 1 + stack_skip)) - local source_lineno=${BASH_LINENO[$((frame_no - 1))]} - local funcname=${FUNCNAME[${frame_no}]} - if [[ "$funcname" =~ 'e2e::' ]]; then - echo "${source_lineno}" - fi - done - fi + local stack_skip=${1:-0} + stack_skip=$((stack_skip + 1)) + if [[ ${#FUNCNAME[@]} -gt ${stack_skip} ]]; then + local i + for ((i=1 ; i <= ${#FUNCNAME[@]} - stack_skip ; i++)); do + local frame_no=$((i - 1 + stack_skip)) + local source_lineno=${BASH_LINENO[$((frame_no - 1))]} + local funcname=${FUNCNAME[${frame_no}]} + if [[ "$funcname" =~ 'e2e::' ]]; then + echo "${source_lineno}" + fi + done + fi } function fail() { @@ -193,8 +192,8 @@ E2E_TAG=$(git rev-parse --show-toplevel | sed 's|/|_|g') # current tree. build_container=false if [[ "${GIT_SYNC_E2E_IMAGE:-unset}" == "unset" ]]; then - GIT_SYNC_E2E_IMAGE="e2e/git-sync:${E2E_TAG}__$(go env GOOS)_$(go env GOARCH)" - build_container=true + GIT_SYNC_E2E_IMAGE="e2e/git-sync:${E2E_TAG}__$(go env GOOS)_$(go env GOARCH)" + build_container=true fi # DIR is the directory in which all this test's state lives. @@ -202,11 +201,11 @@ RUNID="${RANDOM}${RANDOM}" DIR="/tmp/git-sync-e2e.$RUNID" mkdir "$DIR" function final_cleanup() { - if [[ "${CLEANUP:-}" == 0 ]]; then - echo "leaving logs in $DIR" - else - rm -rf "$DIR" - fi + if [[ "${CLEANUP:-}" == 0 ]]; then + echo "leaving logs in $DIR" + else + rm -rf "$DIR" + fi } # Set the trap to call the final_cleanup function on exit. trap final_cleanup EXIT @@ -216,38 +215,38 @@ required_env_vars=() LOCAL_GITHUB_APP_PRIVATE_KEY_FILE="github_app_private_key.pem" GITHUB_APP_PRIVATE_KEY_MOUNT=() if [[ "${skip_github_app_test}" != "true" ]]; then - required_env_vars=( - "TEST_GITHUB_APP_AUTH_TEST_REPO" - "TEST_GITHUB_APP_APPLICATION_ID" - "TEST_GITHUB_APP_INSTALLATION_ID" - "TEST_GITHUB_APP_CLIENT_ID" - ) - - if [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY_FILE:-}" && -n "${TEST_GITHUB_APP_PRIVATE_KEY:-}" ]]; then - echo "ERROR: Both TEST_GITHUB_APP_PRIVATE_KEY_FILE and TEST_GITHUB_APP_PRIVATE_KEY were specified." - exit 1 - fi - if [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY_FILE:-}" ]]; then - cp "${TEST_GITHUB_APP_PRIVATE_KEY_FILE}" "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}" - elif [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY:-}" ]]; then - echo "${TEST_GITHUB_APP_PRIVATE_KEY}" > "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}" - else - echo "ERROR: Neither TEST_GITHUB_APP_PRIVATE_KEY_FILE nor TEST_GITHUB_APP_PRIVATE_KEY was specified." - echo " Either provide a value or skip this test (SKIP_GITHUB_APP_TEST=true)." - exit 1 - fi - - # Validate all required environment variables for the github-app-auth tests are provided. - for var in "${required_env_vars[@]}"; do - if [[ ! -v "${var}" ]]; then - echo "ERROR: Required environment variable '${var}' is not set." - echo " Either provide a value or skip this test (SKIP_GITHUB_APP_TEST=true)." - exit 1 + required_env_vars=( + "TEST_GITHUB_APP_AUTH_TEST_REPO" + "TEST_GITHUB_APP_APPLICATION_ID" + "TEST_GITHUB_APP_INSTALLATION_ID" + "TEST_GITHUB_APP_CLIENT_ID" + ) + + if [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY_FILE:-}" && -n "${TEST_GITHUB_APP_PRIVATE_KEY:-}" ]]; then + echo "ERROR: Both TEST_GITHUB_APP_PRIVATE_KEY_FILE and TEST_GITHUB_APP_PRIVATE_KEY were specified." + exit 1 + fi + if [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY_FILE:-}" ]]; then + cp "${TEST_GITHUB_APP_PRIVATE_KEY_FILE}" "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}" + elif [[ -n "${TEST_GITHUB_APP_PRIVATE_KEY:-}" ]]; then + echo "${TEST_GITHUB_APP_PRIVATE_KEY}" > "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}" + else + echo "ERROR: Neither TEST_GITHUB_APP_PRIVATE_KEY_FILE nor TEST_GITHUB_APP_PRIVATE_KEY was specified." + echo " Either provide a value or skip this test (SKIP_GITHUB_APP_TEST=true)." + exit 1 fi - done - # Mount the GitHub App private key file to the git-sync container - GITHUB_APP_PRIVATE_KEY_MOUNT=(-v "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}":"/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}":ro) + # Validate all required environment variables for the github-app-auth tests are provided. + for var in "${required_env_vars[@]}"; do + if [[ ! -v "${var}" ]]; then + echo "ERROR: Required environment variable '${var}' is not set." + echo " Either provide a value or skip this test (SKIP_GITHUB_APP_TEST=true)." + exit 1 + fi + done + + # Mount the GitHub App private key file to the git-sync container + GITHUB_APP_PRIVATE_KEY_MOUNT=(-v "${DIR}/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}":"/${LOCAL_GITHUB_APP_PRIVATE_KEY_FILE}":ro) fi # WORK is temp space and in reset for each testcase.