]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7060-wtstatus.sh
72fb418b8904ffedac1fcf87d97878c86e054b5b
[thirdparty/git.git] / t / t7060-wtstatus.sh
1 #!/bin/sh
2
3 test_description='basic work tree status reporting'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_expect_success setup '
11 git config --global advice.statusuoption false &&
12 test_commit A &&
13 test_commit B oneside added &&
14 git checkout A^0 &&
15 test_commit C oneside created
16 '
17
18 test_expect_success 'A/A conflict' '
19 git checkout B^0 &&
20 test_must_fail git merge C
21 '
22
23 test_expect_success 'Report path with conflict' '
24 git diff --cached --name-status >actual &&
25 echo "U oneside" >expect &&
26 test_cmp expect actual
27 '
28
29 test_expect_success 'Report new path with conflict' '
30 git diff --cached --name-status HEAD^ >actual &&
31 echo "U oneside" >expect &&
32 test_cmp expect actual
33 '
34
35 test_expect_success 'M/D conflict does not segfault' '
36 cat >expect <<EOF &&
37 On branch side
38 You have unmerged paths.
39 (fix conflicts and run "git commit")
40 (use "git merge --abort" to abort the merge)
41
42 Unmerged paths:
43 (use "git add/rm <file>..." as appropriate to mark resolution)
44 deleted by us: foo
45
46 no changes added to commit (use "git add" and/or "git commit -a")
47 EOF
48 mkdir mdconflict &&
49 (
50 cd mdconflict &&
51 git init &&
52 test_commit initial foo "" &&
53 test_commit modify foo foo &&
54 git checkout -b side HEAD^ &&
55 git rm foo &&
56 git commit -m delete &&
57 test_must_fail git merge main &&
58 test_must_fail git commit --dry-run >../actual &&
59 test_i18ncmp ../expect ../actual &&
60 git status >../actual &&
61 test_i18ncmp ../expect ../actual
62 )
63 '
64
65 test_expect_success 'rename & unmerged setup' '
66 git rm -f -r . &&
67 cat "$TEST_DIRECTORY/README" >ONE &&
68 git add ONE &&
69 test_tick &&
70 git commit -m "One commit with ONE" &&
71
72 echo Modified >TWO &&
73 cat ONE >>TWO &&
74 cat ONE >>THREE &&
75 git add TWO THREE &&
76 sha1=$(git rev-parse :ONE) &&
77 git rm --cached ONE &&
78 (
79 echo "100644 $sha1 1 ONE" &&
80 echo "100644 $sha1 2 ONE" &&
81 echo "100644 $sha1 3 ONE"
82 ) | git update-index --index-info &&
83 echo Further >>THREE
84 '
85
86 test_expect_success 'rename & unmerged status' '
87 git status -suno >actual &&
88 cat >expect <<-EOF &&
89 UU ONE
90 AM THREE
91 A TWO
92 EOF
93 test_cmp expect actual
94 '
95
96 test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' '
97 cat >expected <<-EOF &&
98 U ONE
99 A THREE
100 A TWO
101 EOF
102 git diff-index --cached --name-status HEAD >actual &&
103 test_cmp expected actual
104 '
105
106 test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' '
107 cat >expected <<-EOF &&
108 U ONE
109 A THREE
110 A TWO
111 EOF
112 git diff-index --cached -M --name-status HEAD >actual &&
113 test_cmp expected actual
114 '
115
116 test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' '
117 cat >expected <<-EOF &&
118 U ONE
119 C ONE THREE
120 C ONE TWO
121 EOF
122 git diff-index --cached -C --name-status HEAD |
123 sed "s/^C[0-9]*/C/g" >actual &&
124 test_cmp expected actual
125 '
126
127
128 test_expect_success 'status when conflicts with add and rm advice (deleted by them)' '
129 git reset --hard &&
130 git checkout main &&
131 test_commit init main.txt init &&
132 git checkout -b second_branch &&
133 git rm main.txt &&
134 git commit -m "main.txt deleted on second_branch" &&
135 test_commit second conflict.txt second &&
136 git checkout main &&
137 test_commit on_second main.txt on_second &&
138 test_commit main conflict.txt main &&
139 test_must_fail git merge second_branch &&
140 cat >expected <<\EOF &&
141 On branch main
142 You have unmerged paths.
143 (fix conflicts and run "git commit")
144 (use "git merge --abort" to abort the merge)
145
146 Unmerged paths:
147 (use "git add/rm <file>..." as appropriate to mark resolution)
148 both added: conflict.txt
149 deleted by them: main.txt
150
151 no changes added to commit (use "git add" and/or "git commit -a")
152 EOF
153 git status --untracked-files=no >actual &&
154 test_i18ncmp expected actual
155 '
156
157
158 test_expect_success 'prepare for conflicts' '
159 git reset --hard &&
160 git checkout -b conflict &&
161 test_commit one main.txt one &&
162 git branch conflict_second &&
163 git mv main.txt sub_main.txt &&
164 git commit -m "main.txt renamed in sub_main.txt" &&
165 git checkout conflict_second &&
166 git mv main.txt sub_second.txt &&
167 git commit -m "main.txt renamed in sub_second.txt"
168 '
169
170
171 test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
172 test_must_fail git merge conflict &&
173 cat >expected <<\EOF &&
174 On branch conflict_second
175 You have unmerged paths.
176 (fix conflicts and run "git commit")
177 (use "git merge --abort" to abort the merge)
178
179 Unmerged paths:
180 (use "git add/rm <file>..." as appropriate to mark resolution)
181 both deleted: main.txt
182 added by them: sub_main.txt
183 added by us: sub_second.txt
184
185 no changes added to commit (use "git add" and/or "git commit -a")
186 EOF
187 git status --untracked-files=no >actual &&
188 test_i18ncmp expected actual
189 '
190
191
192 test_expect_success 'status when conflicts with only rm advice (both deleted)' '
193 git reset --hard conflict_second &&
194 test_must_fail git merge conflict &&
195 git add sub_main.txt &&
196 git add sub_second.txt &&
197 cat >expected <<\EOF &&
198 On branch conflict_second
199 You have unmerged paths.
200 (fix conflicts and run "git commit")
201 (use "git merge --abort" to abort the merge)
202
203 Changes to be committed:
204 new file: sub_main.txt
205
206 Unmerged paths:
207 (use "git rm <file>..." to mark resolution)
208 both deleted: main.txt
209
210 Untracked files not listed (use -u option to show untracked files)
211 EOF
212 git status --untracked-files=no >actual &&
213 test_i18ncmp expected actual &&
214 git reset --hard &&
215 git checkout main
216 '
217
218 test_expect_success 'status --branch with detached HEAD' '
219 git reset --hard &&
220 git checkout main^0 &&
221 git status --branch --porcelain >actual &&
222 cat >expected <<-EOF &&
223 ## HEAD (no branch)
224 ?? .gitconfig
225 ?? actual
226 ?? expect
227 ?? expected
228 ?? mdconflict/
229 EOF
230 test_i18ncmp expected actual
231 '
232
233 ## Duplicate the above test and verify --porcelain=v1 arg parsing.
234 test_expect_success 'status --porcelain=v1 --branch with detached HEAD' '
235 git reset --hard &&
236 git checkout main^0 &&
237 git status --branch --porcelain=v1 >actual &&
238 cat >expected <<-EOF &&
239 ## HEAD (no branch)
240 ?? .gitconfig
241 ?? actual
242 ?? expect
243 ?? expected
244 ?? mdconflict/
245 EOF
246 test_i18ncmp expected actual
247 '
248
249 ## Verify parser error on invalid --porcelain argument.
250 test_expect_success 'status --porcelain=bogus' '
251 test_must_fail git status --porcelain=bogus
252 '
253
254 test_done