summaryrefslogtreecommitdiff
path: root/t/t2401-worktree-prune.sh
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2020-06-10 06:30:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-06-10 17:54:49 (GMT)
commit4a3ce479ce7c8f268f42b725e471e35967da9b4f (patch)
treea9cb534d4b64525c3db759c97380d91ac686e901 /t/t2401-worktree-prune.sh
parentdd9609a12e83969be6536853b2846866dafdfc98 (diff)
downloadgit-4a3ce479ce7c8f268f42b725e471e35967da9b4f.zip
git-4a3ce479ce7c8f268f42b725e471e35967da9b4f.tar.gz
git-4a3ce479ce7c8f268f42b725e471e35967da9b4f.tar.bz2
worktree: prune duplicate entries referencing same worktree path
A fundamental restriction of linked working trees is that there must only ever be a single worktree associated with a particular path, thus "git worktree add" explicitly disallows creation of a new worktree at the same location as an existing registered worktree. Nevertheless, users can still "shoot themselves in the foot" by mucking with administrative files in .git/worktree/<id>/. Worse, "git worktree move" is careless[1] and allows a worktree to be moved atop a registered but missing worktree (which can happen, for instance, if the worktree is on removable media). For instance: $ git clone foo.git $ cd foo $ git worktree add ../bar $ git worktree add ../baz $ rm -rf ../bar $ git worktree move ../baz ../bar $ git worktree list .../foo beefd00f [master] .../bar beefd00f [bar] .../bar beefd00f [baz] Help users recover from this form of corruption by teaching "git worktree prune" to detect when multiple worktrees are associated with the same path. [1]: A subsequent commit will fix "git worktree move" validation to be more strict. 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 b7d6d5d..fd3916f 100755
--- a/t/t2401-worktree-prune.sh
+++ b/t/t2401-worktree-prune.sh
@@ -92,4 +92,16 @@ test_expect_success 'not prune proper checkouts' '
test -d .git/worktrees/nop
'
+test_expect_success 'prune duplicate (linked/linked)' '
+ test_when_finished rm -fr .git/worktrees w1 w2 &&
+ git worktree add --detach w1 &&
+ git worktree add --detach w2 &&
+ sed "s/w2/w1/" .git/worktrees/w2/gitdir >.git/worktrees/w2/gitdir.new &&
+ mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir &&
+ git worktree prune --verbose >actual &&
+ test_i18ngrep "duplicate entry" actual &&
+ test -d .git/worktrees/w1 &&
+ ! test -d .git/worktrees/w2
+'
+
test_done