summaryrefslogtreecommitdiff
path: root/t/t2401-worktree-prune.sh
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2020-06-10 02:30:47 -0400
committerJunio C Hamano <gitster@pobox.com>2020-06-10 10:54:49 -0700
commit916133ef8edcda54b0bff03a949c0858cd8d3280 (patch)
treeb2132f371b5e1f54dfce5d1e5c8f7444ef2c09c1 /t/t2401-worktree-prune.sh
parent4a3ce479ce7c8f268f42b725e471e35967da9b4f (diff)
downloadgit-916133ef8edcda54b0bff03a949c0858cd8d3280.tar.gz
worktree: prune linked worktree referencing main worktree path
"git worktree prune" detects when multiple entries are associated with the same path and prunes the duplicates, however, it does not detect when a linked worktree points at the path of the main worktree. Although "git worktree add" disallows creating a new worktree with the same path as the main worktree, such a case can arise outside the control of Git even without the user mucking with .git/worktree/<id>/ administrative files. For instance: $ git clone foo.git $ git -C foo worktree add ../bar $ rm -rf bar $ mv foo bar $ git -C bar worktree list .../bar deadfeeb [master] .../bar deadfeeb [bar] Help the user recover from such corruption by extending "git worktree prune" to also detect when a linked worktree is associated with the path of the main worktree. Reported-by: Jonathan Müller <jonathanmueller.dev@gmail.com> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t2401-worktree-prune.sh')
-rwxr-xr-xt/t2401-worktree-prune.sh12
1 files changed, 12 insertions, 0 deletions
diff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh
index fd3916fee0..a6ce7f590b 100755
--- a/t/t2401-worktree-prune.sh
+++ b/t/t2401-worktree-prune.sh
@@ -104,4 +104,16 @@ test_expect_success 'prune duplicate (linked/linked)' '
! test -d .git/worktrees/w2
'
+test_expect_success 'prune duplicate (main/linked)' '
+ test_when_finished rm -fr repo wt &&
+ test_create_repo repo &&
+ test_commit -C repo x &&
+ git -C repo worktree add --detach ../wt &&
+ rm -fr wt &&
+ mv repo wt &&
+ git -C wt worktree prune --verbose >actual &&
+ test_i18ngrep "duplicate entry" actual &&
+ ! test -d .git/worktrees/wt
+'
+
test_done