t2028: fix minor error and issues in newly-added "worktree move" tests
[git.git] / t / t2028-worktree-move.sh
blob5d5b3632ba0a7cf5364ab4db1df8ca7ea285b4d5
1 #!/bin/sh
3 test_description='test git worktree move, remove, lock and unlock'
5 . ./test-lib.sh
7 test_expect_success 'setup' '
8 test_commit init &&
9 git worktree add source &&
10 git worktree list --porcelain >out &&
11 grep "^worktree" out >actual &&
12 cat <<-EOF >expected &&
13 worktree $(pwd)
14 worktree $(pwd)/source
15 EOF
16 test_cmp expected actual
19 test_expect_success 'lock main worktree' '
20 test_must_fail git worktree lock .
23 test_expect_success 'lock linked worktree' '
24 git worktree lock --reason hahaha source &&
25 echo hahaha >expected &&
26 test_cmp expected .git/worktrees/source/locked
29 test_expect_success 'lock linked worktree from another worktree' '
30 rm .git/worktrees/source/locked &&
31 git worktree add elsewhere &&
32 git -C elsewhere worktree lock --reason hahaha ../source &&
33 echo hahaha >expected &&
34 test_cmp expected .git/worktrees/source/locked
37 test_expect_success 'lock worktree twice' '
38 test_must_fail git worktree lock source &&
39 echo hahaha >expected &&
40 test_cmp expected .git/worktrees/source/locked
43 test_expect_success 'lock worktree twice (from the locked worktree)' '
44 test_must_fail git -C source worktree lock . &&
45 echo hahaha >expected &&
46 test_cmp expected .git/worktrees/source/locked
49 test_expect_success 'unlock main worktree' '
50 test_must_fail git worktree unlock .
53 test_expect_success 'unlock linked worktree' '
54 git worktree unlock source &&
55 test_path_is_missing .git/worktrees/source/locked
58 test_expect_success 'unlock worktree twice' '
59 test_must_fail git worktree unlock source &&
60 test_path_is_missing .git/worktrees/source/locked
63 test_expect_success 'move non-worktree' '
64 mkdir abc &&
65 test_must_fail git worktree move abc def
68 test_expect_success 'move locked worktree' '
69 git worktree lock source &&
70 test_when_finished "git worktree unlock source" &&
71 test_must_fail git worktree move source destination
74 test_expect_success 'move worktree' '
75 toplevel="$(pwd)" &&
76 git worktree move source destination &&
77 test_path_is_missing source &&
78 git worktree list --porcelain >out &&
79 grep "^worktree.*/destination" out &&
80 ! grep "^worktree.*/source" out &&
81 git -C destination log --format=%s >actual2 &&
82 echo init >expected2 &&
83 test_cmp expected2 actual2
86 test_expect_success 'move main worktree' '
87 test_must_fail git worktree move . def
90 test_expect_success 'move worktree to another dir' '
91 mkdir some-dir &&
92 git worktree move destination some-dir &&
93 test_when_finished "git worktree move some-dir/destination destination" &&
94 test_path_is_missing destination &&
95 git worktree list --porcelain >out &&
96 grep "^worktree.*/some-dir/destination" out &&
97 git -C some-dir/destination log --format=%s >actual2 &&
98 echo init >expected2 &&
99 test_cmp expected2 actual2
102 test_expect_success 'remove main worktree' '
103 test_must_fail git worktree remove .
106 test_expect_success 'remove locked worktree' '
107 git worktree lock destination &&
108 test_when_finished "git worktree unlock destination" &&
109 test_must_fail git worktree remove destination
112 test_expect_success 'remove worktree with dirty tracked file' '
113 echo dirty >>destination/init.t &&
114 test_when_finished "git -C destination checkout init.t" &&
115 test_must_fail git worktree remove destination
118 test_expect_success 'remove worktree with untracked file' '
119 : >destination/untracked &&
120 test_must_fail git worktree remove destination
123 test_expect_success 'force remove worktree with untracked file' '
124 git worktree remove --force destination &&
125 test_path_is_missing destination
128 test_expect_success 'remove missing worktree' '
129 git worktree add to-be-gone &&
130 test -d .git/worktrees/to-be-gone &&
131 mv to-be-gone gone &&
132 git worktree remove to-be-gone &&
133 test_path_is_missing .git/worktrees/to-be-gone
136 test_expect_success 'NOT remove missing-but-locked worktree' '
137 git worktree add gone-but-locked &&
138 git worktree lock gone-but-locked &&
139 test -d .git/worktrees/gone-but-locked &&
140 mv gone-but-locked really-gone-now &&
141 test_must_fail git worktree remove gone-but-locked &&
142 test_path_is_dir .git/worktrees/gone-but-locked
145 test_done