Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e case for missing worktree after crash #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 32 additions & 1 deletion test_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
##############################################
Expand Down
Loading