Add e2e case for missing worktree after crash

This commit is contained in:
Tim Hockin 2023-10-13 13:33:33 -07:00
parent b69d0f3bac
commit 1a5daeaf43
2 changed files with 35 additions and 1 deletions

View File

@ -1681,6 +1681,9 @@ 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.
// We can end up here with no current hash but (the expectation of) a
// current worktree (e.g. the hash was synced but the worktree does not
// exist).
if currentHash != "" && 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.

View File

@ -1297,7 +1297,7 @@ function e2e::sync_sha_once_sync_different_sha_unknown() {
############################################## ##############################################
# Test syncing after a crash # Test syncing after a crash
############################################## ##############################################
function e2e::sync_crash_cleanup_retry() { function e2e::sync_crash_no_link_cleanup_retry() {
# First sync # First sync
echo "$FUNCNAME 1" > "$REPO/file" echo "$FUNCNAME 1" > "$REPO/file"
git -C "$REPO" commit -qam "$FUNCNAME 1" git -C "$REPO" commit -qam "$FUNCNAME 1"
@ -1325,6 +1325,37 @@ function e2e::sync_crash_cleanup_retry() {
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1" assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
} }
##############################################
# Test syncing after a crash
##############################################
function e2e::sync_crash_no_worktree_cleanup_retry() {
# First sync
echo "$FUNCNAME 1" > "$REPO/file"
git -C "$REPO" commit -qam "$FUNCNAME 1"
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link"
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
# Corrupt it
rm -rf "$ROOT/.worktrees/"
# Try again
GIT_SYNC \
--one-time \
--repo="file://$REPO" \
--root="$ROOT" \
--link="link"
assert_link_exists "$ROOT/link"
assert_file_exists "$ROOT/link/file"
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
}
############################################## ##############################################
# Test changing repos with storage intact # Test changing repos with storage intact
############################################## ##############################################