Recover if wrong worktree HEAD
This commit is contained in:
parent
befdbfff31
commit
83bd660494
11
main.go
11
main.go
|
|
@ -1188,6 +1188,17 @@ func (git *repoSync) sanityCheckWorktree(ctx context.Context, worktree worktree)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure it is synced to the right commmit.
|
||||||
|
stdout, _, err := git.Run(ctx, worktree.Path(), "rev-parse", "HEAD")
|
||||||
|
if err != nil {
|
||||||
|
git.log.Error(err, "can't get worktree HEAD", "path", worktree.Path())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if stdout != worktree.Hash() {
|
||||||
|
git.log.V(0).Info("worktree HEAD does not match worktree", "path", worktree.Path(), "head", stdout)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Consistency-check the worktree. Don't use --verbose because it can be
|
// Consistency-check the worktree. Don't use --verbose because it can be
|
||||||
// REALLY verbose.
|
// REALLY verbose.
|
||||||
if _, _, err := git.Run(ctx, worktree.Path(), "fsck", "--no-progress", "--connectivity-only"); err != nil {
|
if _, _, err := git.Run(ctx, worktree.Path(), "fsck", "--no-progress", "--connectivity-only"); err != nil {
|
||||||
|
|
|
||||||
63
test_e2e.sh
63
test_e2e.sh
|
|
@ -609,7 +609,7 @@ function e2e::worktree_cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
# Test worktree-unexpected-removal
|
# Test worktree unexpected removal
|
||||||
##############################################
|
##############################################
|
||||||
function e2e::worktree_unexpected_removal() {
|
function e2e::worktree_unexpected_removal() {
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
|
|
@ -635,7 +635,52 @@ function e2e::worktree_unexpected_removal() {
|
||||||
|
|
||||||
# make a unexpected removal
|
# make a unexpected removal
|
||||||
WT=$(git -C "$REPO" rev-list -n1 HEAD)
|
WT=$(git -C "$REPO" rev-list -n1 HEAD)
|
||||||
rm -r "$ROOT/.worktrees/$WT"
|
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 syncing when the worktree is wrong hash
|
||||||
|
##############################################
|
||||||
|
function e2e::sync_recover_wrong_worktree_hash() {
|
||||||
|
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
|
||||||
|
|
||||||
|
# Corrupt it
|
||||||
|
echo "unexpected" > "$ROOT/link/file"
|
||||||
|
git -C "$ROOT/link" commit -qam "corrupt it"
|
||||||
|
|
||||||
# resume time
|
# resume time
|
||||||
docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \
|
docker ps --filter label="git-sync-e2e=$RUNID" --format="{{.ID}}" \
|
||||||
|
|
@ -1294,9 +1339,6 @@ function e2e::sync_sha_once_sync_different_sha_unknown() {
|
||||||
##############################################
|
##############################################
|
||||||
function e2e::sync_crash_no_link_cleanup_retry() {
|
function e2e::sync_crash_no_link_cleanup_retry() {
|
||||||
# First sync
|
# First sync
|
||||||
echo "$FUNCNAME 1" > "$REPO/file"
|
|
||||||
git -C "$REPO" commit -qam "$FUNCNAME 1"
|
|
||||||
|
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
|
@ -1304,7 +1346,7 @@ function e2e::sync_crash_no_link_cleanup_retry() {
|
||||||
--link="link"
|
--link="link"
|
||||||
assert_link_exists "$ROOT/link"
|
assert_link_exists "$ROOT/link"
|
||||||
assert_file_exists "$ROOT/link/file"
|
assert_file_exists "$ROOT/link/file"
|
||||||
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
|
|
||||||
# Corrupt it
|
# Corrupt it
|
||||||
rm -f "$ROOT/link"
|
rm -f "$ROOT/link"
|
||||||
|
|
@ -1317,7 +1359,7 @@ function e2e::sync_crash_no_link_cleanup_retry() {
|
||||||
--link="link"
|
--link="link"
|
||||||
assert_link_exists "$ROOT/link"
|
assert_link_exists "$ROOT/link"
|
||||||
assert_file_exists "$ROOT/link/file"
|
assert_file_exists "$ROOT/link/file"
|
||||||
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
|
|
@ -1325,9 +1367,6 @@ function e2e::sync_crash_no_link_cleanup_retry() {
|
||||||
##############################################
|
##############################################
|
||||||
function e2e::sync_crash_no_worktree_cleanup_retry() {
|
function e2e::sync_crash_no_worktree_cleanup_retry() {
|
||||||
# First sync
|
# First sync
|
||||||
echo "$FUNCNAME 1" > "$REPO/file"
|
|
||||||
git -C "$REPO" commit -qam "$FUNCNAME 1"
|
|
||||||
|
|
||||||
GIT_SYNC \
|
GIT_SYNC \
|
||||||
--one-time \
|
--one-time \
|
||||||
--repo="file://$REPO" \
|
--repo="file://$REPO" \
|
||||||
|
|
@ -1335,7 +1374,7 @@ function e2e::sync_crash_no_worktree_cleanup_retry() {
|
||||||
--link="link"
|
--link="link"
|
||||||
assert_link_exists "$ROOT/link"
|
assert_link_exists "$ROOT/link"
|
||||||
assert_file_exists "$ROOT/link/file"
|
assert_file_exists "$ROOT/link/file"
|
||||||
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
|
|
||||||
# Corrupt it
|
# Corrupt it
|
||||||
rm -rf "$ROOT/.worktrees/"
|
rm -rf "$ROOT/.worktrees/"
|
||||||
|
|
@ -1348,7 +1387,7 @@ function e2e::sync_crash_no_worktree_cleanup_retry() {
|
||||||
--link="link"
|
--link="link"
|
||||||
assert_link_exists "$ROOT/link"
|
assert_link_exists "$ROOT/link"
|
||||||
assert_file_exists "$ROOT/link/file"
|
assert_file_exists "$ROOT/link/file"
|
||||||
assert_file_eq "$ROOT/link/file" "$FUNCNAME 1"
|
assert_file_eq "$ROOT/link/file" "$FUNCNAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
##############################################
|
##############################################
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue