From 1a5daeaf43551138edba21efde5c393c1f377183 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 13 Oct 2023 13:33:33 -0700 Subject: [PATCH] Add e2e case for missing worktree after crash --- main.go | 3 +++ test_e2e.sh | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f2aebdb..8d5ee30 100644 --- a/main.go +++ b/main.go @@ -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 // 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) { // The old worktree might have come from a prior version, and so // not get caught by the normal cleanup. diff --git a/test_e2e.sh b/test_e2e.sh index 9ac063f..23d625f 100755 --- a/test_e2e.sh +++ b/test_e2e.sh @@ -1297,7 +1297,7 @@ function e2e::sync_sha_once_sync_different_sha_unknown() { ############################################## # Test syncing after a crash ############################################## -function e2e::sync_crash_cleanup_retry() { +function e2e::sync_crash_no_link_cleanup_retry() { # First sync echo "$FUNCNAME 1" > "$REPO/file" 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" } +############################################## +# 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 ##############################################