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