Merge branch 'es/worktree-forced-ops-fix'
Fix a bug in which the same path could be registered under multiple worktree entries if the path was missing (for instance, was removed manually). Also, as a convenience, expand the number of cases in which --force is applicable. * es/worktree-forced-ops-fix: doc-diff: force worktree add worktree: delete .git/worktrees if empty after 'remove' worktree: teach 'remove' to override lock when --force given twice worktree: teach 'move' to override lock when --force given twice worktree: teach 'add' to respect --force for registered but missing path worktree: disallow adding same path multiple times worktree: prepare for more checks of whether path can become worktree worktree: generalize delete_git_dir() to reduce code duplication worktree: move delete_git_dir() earlier in file for upcoming new callers worktree: don't die() in library function find_worktree()
This commit is contained in:
@ -552,4 +552,22 @@ test_expect_success '"add" in bare repo invokes post-checkout hook' '
|
||||
test_cmp hook.expect goozy/hook.actual
|
||||
'
|
||||
|
||||
test_expect_success '"add" an existing but missing worktree' '
|
||||
git worktree add --detach pneu &&
|
||||
test_must_fail git worktree add --detach pneu &&
|
||||
rm -fr pneu &&
|
||||
test_must_fail git worktree add --detach pneu &&
|
||||
git worktree add --force --detach pneu
|
||||
'
|
||||
|
||||
test_expect_success '"add" an existing locked but missing worktree' '
|
||||
git worktree add --detach gnoo &&
|
||||
git worktree lock gnoo &&
|
||||
test_when_finished "git worktree unlock gnoo || :" &&
|
||||
rm -fr gnoo &&
|
||||
test_must_fail git worktree add --detach gnoo &&
|
||||
test_must_fail git worktree add --force --detach gnoo &&
|
||||
git worktree add --force --force --detach gnoo
|
||||
'
|
||||
|
||||
test_done
|
||||
|
@ -98,6 +98,20 @@ test_expect_success 'move worktree to another dir' '
|
||||
test_cmp expected2 actual2
|
||||
'
|
||||
|
||||
test_expect_success 'move locked worktree (force)' '
|
||||
test_when_finished "
|
||||
git worktree unlock flump || :
|
||||
git worktree remove flump || :
|
||||
git worktree unlock ploof || :
|
||||
git worktree remove ploof || :
|
||||
" &&
|
||||
git worktree add --detach flump &&
|
||||
git worktree lock flump &&
|
||||
test_must_fail git worktree move flump ploof" &&
|
||||
test_must_fail git worktree move --force flump ploof" &&
|
||||
git worktree move --force --force flump ploof
|
||||
'
|
||||
|
||||
test_expect_success 'remove main worktree' '
|
||||
test_must_fail git worktree remove .
|
||||
'
|
||||
@ -141,4 +155,34 @@ test_expect_success 'NOT remove missing-but-locked worktree' '
|
||||
test_path_is_dir .git/worktrees/gone-but-locked
|
||||
'
|
||||
|
||||
test_expect_success 'proper error when worktree not found' '
|
||||
for i in noodle noodle/bork
|
||||
do
|
||||
test_must_fail git worktree lock $i 2>err &&
|
||||
test_i18ngrep "not a working tree" err || return 1
|
||||
done
|
||||
'
|
||||
|
||||
test_expect_success 'remove locked worktree (force)' '
|
||||
git worktree add --detach gumby &&
|
||||
test_when_finished "git worktree remove gumby || :" &&
|
||||
git worktree lock gumby &&
|
||||
test_when_finished "git worktree unlock gumby || :" &&
|
||||
test_must_fail git worktree remove gumby &&
|
||||
test_must_fail git worktree remove --force gumby &&
|
||||
git worktree remove --force --force gumby
|
||||
'
|
||||
|
||||
test_expect_success 'remove cleans up .git/worktrees when empty' '
|
||||
git init moog &&
|
||||
(
|
||||
cd moog &&
|
||||
test_commit bim &&
|
||||
git worktree add --detach goom &&
|
||||
test_path_exists .git/worktrees &&
|
||||
git worktree remove goom &&
|
||||
test_path_is_missing .git/worktrees
|
||||
)
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user