fix: infinite bad loop caused by unexpected worktree directory removal
This commit is contained in:
parent
6426efe346
commit
ff51ca92dc
2
main.go
2
main.go
|
|
@ -2038,7 +2038,7 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con
|
||||||
// Regular cleanup will happen in the outer loop, to catch stale
|
// Regular cleanup will happen in the outer loop, to catch stale
|
||||||
// worktrees.
|
// worktrees.
|
||||||
|
|
||||||
if currentWorktree != git.worktreeFor(currentHash) {
|
if currentHash != "" && currentWorktree != git.worktreeFor(currentHash) {
|
||||||
// The old worktree might have come from a prior version, and so
|
// The old worktree might have come from a prior version, and so
|
||||||
// not get caught by the normal cleanup.
|
// not get caught by the normal cleanup.
|
||||||
os.RemoveAll(currentWorktree.Path().String())
|
os.RemoveAll(currentWorktree.Path().String())
|
||||||
|
|
|
||||||
45
test_e2e.sh
45
test_e2e.sh
|
|
@ -608,6 +608,51 @@ function e2e::worktree_cleanup() {
|
||||||
assert_file_absent "$ROOT/.worktrees/not_a_directory"
|
assert_file_absent "$ROOT/.worktrees/not_a_directory"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##############################################
|
||||||
|
# Test worktree-unexpected-removal
|
||||||
|
##############################################
|
||||||
|
function e2e::worktree_unexpected_removal() {
|
||||||
|
GIT_SYNC \
|
||||||
|
--period=100ms \
|
||||||
|
--repo="file://$REPO" \
|
||||||
|
--root="$ROOT" \
|
||||||
|
--link="link" \
|
||||||
|
&
|
||||||
|
|
||||||
|
# wait for first sync
|
||||||
|
wait_for_sync "${MAXWAIT}"
|
||||||
|
assert_link_exists "$ROOT/link"
|
||||||
|
assert_file_exists "$ROOT/link/file"
|
||||||
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
|
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 1
|
||||||
|
assert_metric_eq "${METRIC_FETCH_COUNT}" 1
|
||||||
|
|
||||||
|
# suspend time so we can fake corruption
|
||||||
|
docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \
|
||||||
|
| while read 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"
|
||||||
|
|
||||||
|
# resume time
|
||||||
|
docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \
|
||||||
|
| while read CTR; do
|
||||||
|
docker unpause "$CTR" >/dev/null
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$METRIC_GOOD_SYNC_COUNT"
|
||||||
|
|
||||||
|
wait_for_sync "${MAXWAIT}"
|
||||||
|
assert_link_exists "$ROOT/link"
|
||||||
|
assert_file_exists "$ROOT/link/file"
|
||||||
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
|
assert_metric_eq "${METRIC_GOOD_SYNC_COUNT}" 2
|
||||||
|
assert_metric_eq "${METRIC_FETCH_COUNT}" 2
|
||||||
|
}
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Test stale-worktree-timeout
|
# Test stale-worktree-timeout
|
||||||
##############################################
|
##############################################
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue