3 test_description='test git worktree move, remove, lock and unlock'
7 test_expect_success 'setup' '
9 git worktree add source &&
10 git worktree list --porcelain | grep "^worktree" >actual &&
11 cat <<-EOF >expected &&
13 worktree $(pwd)/source
15 test_cmp expected actual
18 test_expect_success 'lock main worktree' '
19 test_must_fail git worktree lock .
22 test_expect_success 'lock linked worktree' '
23 git worktree lock --reason hahaha source &&
24 echo hahaha >expected &&
25 test_cmp expected .git/worktrees/source/locked
28 test_expect_success 'lock linked worktree from another worktree' '
29 rm .git/worktrees/source/locked &&
30 git worktree add elsewhere &&
31 git -C elsewhere worktree lock --reason hahaha ../source &&
32 echo hahaha >expected &&
33 test_cmp expected .git/worktrees/source/locked
36 test_expect_success 'lock worktree twice' '
37 test_must_fail git worktree lock source &&
38 echo hahaha >expected &&
39 test_cmp expected .git/worktrees/source/locked
42 test_expect_success 'lock worktree twice (from the locked worktree)' '
43 test_must_fail git -C source worktree lock . &&
44 echo hahaha >expected &&
45 test_cmp expected .git/worktrees/source/locked
48 test_expect_success 'unlock main worktree' '
49 test_must_fail git worktree unlock .
52 test_expect_success 'unlock linked worktree' '
53 git worktree unlock source &&
54 test_path_is_missing .git/worktrees/source/locked
57 test_expect_success 'unlock worktree twice' '
58 test_must_fail git worktree unlock source &&
59 test_path_is_missing .git/worktrees/source/locked
62 test_expect_success 'move non-worktree' '
64 test_must_fail git worktree move abc def
67 test_expect_success 'move locked worktree' '
68 git worktree lock source &&
69 test_when_finished "git worktree unlock source" &&
70 test_must_fail git worktree move source destination
73 test_expect_success 'move worktree' '
75 git worktree move source destination &&
76 test_path_is_missing source &&
77 git worktree list --porcelain | grep "^worktree.*/destination" &&
78 ! git worktree list --porcelain | grep "^worktree.*/source" >empty &&
79 git -C destination log --format=%s >actual2 &&
80 echo init >expected2 &&
81 test_cmp expected2 actual2
84 test_expect_success 'move main worktree' '
85 test_must_fail git worktree move . def
88 test_expect_success 'move worktree to another dir' '
91 git worktree move destination some-dir &&
92 test_path_is_missing source &&
93 git worktree list --porcelain | grep "^worktree.*/some-dir/destination" &&
94 git -C some-dir/destination log --format=%s >actual2 &&
95 echo init >expected2 &&
96 test_cmp expected2 actual2
99 test_expect_success 'remove main worktree' '
100 test_must_fail git worktree remove .
103 test_expect_success 'move some-dir/destination back' '
104 git worktree move some-dir/destination destination
107 test_expect_success 'remove locked worktree' '
108 git worktree lock destination &&
109 test_when_finished "git worktree unlock destination" &&
110 test_must_fail git worktree remove destination
113 test_expect_success 'remove worktree with dirty tracked file' '
114 echo dirty >>destination/init.t &&
115 test_when_finished "git -C destination checkout init.t" &&
116 test_must_fail git worktree remove destination
119 test_expect_success 'remove worktree with untracked file' '
120 : >destination/untracked &&
121 test_must_fail git worktree remove destination
124 test_expect_success 'force remove worktree with untracked file' '
125 git worktree remove --force destination &&
126 test_path_is_missing destination
129 test_expect_success 'remove missing worktree' '
130 git worktree add to-be-gone &&
131 test -d .git/worktrees/to-be-gone &&
132 mv to-be-gone gone &&
133 git worktree remove to-be-gone &&
134 test_path_is_missing .git/worktrees/to-be-gone
137 test_expect_success 'NOT remove missing-but-locked worktree' '
138 git worktree add gone-but-locked &&
139 git worktree lock gone-but-locked &&
140 test -d .git/worktrees/gone-but-locked &&
141 mv gone-but-locked really-gone-now &&
142 test_must_fail git worktree remove gone-but-locked &&
143 test_path_is_dir .git/worktrees/gone-but-locked