Skip to content

Commit 1a5daea

Browse files
committed
Add e2e case for missing worktree after crash
1 parent b69d0f3 commit 1a5daea

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,6 +1681,9 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con
16811681
// Regular cleanup will happen in the outer loop, to catch stale
16821682
// worktrees.
16831683

1684+
// We can end up here with no current hash but (the expectation of) a
1685+
// current worktree (e.g. the hash was synced but the worktree does not
1686+
// exist).
16841687
if currentHash != "" && currentWorktree != git.worktreeFor(currentHash) {
16851688
// The old worktree might have come from a prior version, and so
16861689
// not get caught by the normal cleanup.

test_e2e.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ function e2e::sync_sha_once_sync_different_sha_unknown() {
12971297
##############################################
12981298
# Test syncing after a crash
12991299
##############################################
1300-
function e2e::sync_crash_cleanup_retry() {
1300+
function e2e::sync_crash_no_link_cleanup_retry() {
13011301
# First sync
13021302
echo "$FUNCNAME 1" > "$REPO/file"
13031303
git -C "$REPO" commit -qam "$FUNCNAME 1"
@@ -1325,6 +1325,37 @@ function e2e::sync_crash_cleanup_retry() {
13251325
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
13261326
}
13271327

1328+
##############################################
1329+
# Test syncing after a crash
1330+
##############################################
1331+
function e2e::sync_crash_no_worktree_cleanup_retry() {
1332+
# First sync
1333+
echo "$FUNCNAME 1" > "$REPO/file"
1334+
git -C "$REPO" commit -qam "$FUNCNAME 1"
1335+
1336+
GIT_SYNC \
1337+
--one-time \
1338+
--repo="file://$REPO" \
1339+
--root="$ROOT" \
1340+
--link="link"
1341+
assert_link_exists "$ROOT/link"
1342+
assert_file_exists "$ROOT/link/file"
1343+
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
1344+
1345+
# Corrupt it
1346+
rm -rf "$ROOT/.worktrees/"
1347+
1348+
# Try again
1349+
GIT_SYNC \
1350+
--one-time \
1351+
--repo="file://$REPO" \
1352+
--root="$ROOT" \
1353+
--link="link"
1354+
assert_link_exists "$ROOT/link"
1355+
assert_file_exists "$ROOT/link/file"
1356+
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
1357+
}
1358+
13281359
##############################################
13291360
# Test changing repos with storage intact
13301361
##############################################

0 commit comments

Comments
 (0)