Browse Source
"git worktree prune" protected worktrees that are marked as "locked" by creating a file in a known location. "git worktree" command learned a dedicated command pair to create and remove such a file, so that the users do not have to do this with editor. * nd/worktree-lock: worktree.c: find_worktree() search by path suffix worktree: add "unlock" command worktree: add "lock" command worktree.c: add is_worktree_locked() worktree.c: add is_main_worktree() worktree.c: add find_worktree()maint
Junio C Hamano
9 years ago
6 changed files with 260 additions and 7 deletions
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh |
||||
|
||||
test_description='test git worktree move, remove, lock and unlock' |
||||
|
||||
. ./test-lib.sh |
||||
|
||||
test_expect_success 'setup' ' |
||||
test_commit init && |
||||
git worktree add source && |
||||
git worktree list --porcelain | grep "^worktree" >actual && |
||||
cat <<-EOF >expected && |
||||
worktree $(pwd) |
||||
worktree $(pwd)/source |
||||
EOF |
||||
test_cmp expected actual |
||||
' |
||||
|
||||
test_expect_success 'lock main worktree' ' |
||||
test_must_fail git worktree lock . |
||||
' |
||||
|
||||
test_expect_success 'lock linked worktree' ' |
||||
git worktree lock --reason hahaha source && |
||||
echo hahaha >expected && |
||||
test_cmp expected .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_expect_success 'lock linked worktree from another worktree' ' |
||||
rm .git/worktrees/source/locked && |
||||
git worktree add elsewhere && |
||||
git -C elsewhere worktree lock --reason hahaha ../source && |
||||
echo hahaha >expected && |
||||
test_cmp expected .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_expect_success 'lock worktree twice' ' |
||||
test_must_fail git worktree lock source && |
||||
echo hahaha >expected && |
||||
test_cmp expected .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_expect_success 'lock worktree twice (from the locked worktree)' ' |
||||
test_must_fail git -C source worktree lock . && |
||||
echo hahaha >expected && |
||||
test_cmp expected .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_expect_success 'unlock main worktree' ' |
||||
test_must_fail git worktree unlock . |
||||
' |
||||
|
||||
test_expect_success 'unlock linked worktree' ' |
||||
git worktree unlock source && |
||||
test_path_is_missing .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_expect_success 'unlock worktree twice' ' |
||||
test_must_fail git worktree unlock source && |
||||
test_path_is_missing .git/worktrees/source/locked |
||||
' |
||||
|
||||
test_done |
Loading…
Reference in new issue