]> git.ipfire.org Git - thirdparty/git.git/commit
worktree: prune linked worktree referencing main worktree path
authorEric Sunshine <sunshine@sunshineco.com>
Wed, 10 Jun 2020 06:30:47 +0000 (02:30 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 10 Jun 2020 17:54:49 +0000 (10:54 -0700)
commit916133ef8edcda54b0bff03a949c0858cd8d3280
treeb2132f371b5e1f54dfce5d1e5c8f7444ef2c09c1
parent4a3ce479ce7c8f268f42b725e471e35967da9b4f
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>
builtin/worktree.c
t/t2401-worktree-prune.sh