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