worktree add: be tolerant of corrupt worktrees
commit105df73e71a9eb901d7ca96f12ce3645729ae486
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 13 May 2019 10:49:44 +0000 (13 17:49 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 May 2019 05:17:18 +0000 (15 14:17 +0900)
treed29c7f1b342b5fe01913f40600af74d772a21b12
parentaeb582a98374c094361cba1bd756dc6307432c42
worktree add: be tolerant of corrupt worktrees

find_worktree() can die() unexpectedly because it uses real_path()
instead of the gentler version. When it's used in 'git worktree add' [1]
and there's a bad worktree, this die() could prevent people from adding
new worktrees.

The "bad" condition to trigger this is when a parent of the worktree's
location is deleted. Then real_path() will complain.

Use the other version so that bad worktrees won't affect 'worktree
add'. The bad ones will eventually be pruned, we just have to tolerate
them for a bit.

[1] added in cb56f55c16 (worktree: disallow adding same path multiple
    times, 2018-08-28), or since v2.20.0. Though the real bug in
    find_worktree() is much older.

Reported-by: Shaheed Haque <shaheedhaque@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t2025-worktree-add.sh
worktree.c