]>
Commit | Line | Data |
---|---|---|
29796c6c JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic work tree status reporting' | |
4 | ||
01dc8133 | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
7 | ||
29796c6c JH |
8 | . ./test-lib.sh |
9 | ||
10 | test_expect_success setup ' | |
6a38ef2c | 11 | git config --global advice.statusuoption false && |
29796c6c JH |
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 | ||
1c7969c9 MM |
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") | |
b0a61ab2 | 40 | (use "git merge --abort" to abort the merge) |
1c7969c9 MM |
41 | |
42 | Unmerged paths: | |
43 | (use "git add/rm <file>..." as appropriate to mark resolution) | |
c7cb333f | 44 | deleted by us: foo |
1c7969c9 | 45 | |
4d4d5726 JH |
46 | no changes added to commit (use "git add" and/or "git commit -a") |
47 | EOF | |
4d4d5726 JH |
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 && | |
01dc8133 | 57 | test_must_fail git merge main && |
9e4b7ab6 | 58 | test_must_fail git commit --dry-run >../actual && |
1108cea7 | 59 | test_cmp ../expect ../actual && |
9e4b7ab6 | 60 | git status >../actual && |
1108cea7 | 61 | test_cmp ../expect ../actual |
9e4b7ab6 | 62 | ) |
4d4d5726 JH |
63 | ' |
64 | ||
d7c9bf22 MZ |
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 | |
b894d3e7 | 112 | git diff-index --cached -M --name-status HEAD >actual && |
d7c9bf22 MZ |
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 | ||
83c750ac LK |
127 | |
128 | test_expect_success 'status when conflicts with add and rm advice (deleted by them)' ' | |
129 | git reset --hard && | |
01dc8133 | 130 | git checkout main && |
83c750ac LK |
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 && | |
01dc8133 | 136 | git checkout main && |
83c750ac | 137 | test_commit on_second main.txt on_second && |
01dc8133 | 138 | test_commit main conflict.txt main && |
83c750ac | 139 | test_must_fail git merge second_branch && |
1c7969c9 | 140 | cat >expected <<\EOF && |
01dc8133 | 141 | On branch main |
1c7969c9 MM |
142 | You have unmerged paths. |
143 | (fix conflicts and run "git commit") | |
b0a61ab2 | 144 | (use "git merge --abort" to abort the merge) |
1c7969c9 MM |
145 | |
146 | Unmerged paths: | |
147 | (use "git add/rm <file>..." as appropriate to mark resolution) | |
c7cb333f JH |
148 | both added: conflict.txt |
149 | deleted by them: main.txt | |
1c7969c9 MM |
150 | |
151 | no changes added to commit (use "git add" and/or "git commit -a") | |
152 | EOF | |
83c750ac | 153 | git status --untracked-files=no >actual && |
1108cea7 | 154 | test_cmp expected actual |
83c750ac LK |
155 | ' |
156 | ||
157 | ||
96b0ec1a | 158 | test_expect_success 'prepare for conflicts' ' |
83c750ac LK |
159 | git reset --hard && |
160 | git checkout -b conflict && | |
161 | test_commit one main.txt one && | |
162 | git branch conflict_second && | |
01dc8133 JS |
163 | git mv main.txt sub_main.txt && |
164 | git commit -m "main.txt renamed in sub_main.txt" && | |
83c750ac LK |
165 | git checkout conflict_second && |
166 | git mv main.txt sub_second.txt && | |
96b0ec1a LK |
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)' ' | |
83c750ac | 172 | test_must_fail git merge conflict && |
1c7969c9 MM |
173 | cat >expected <<\EOF && |
174 | On branch conflict_second | |
175 | You have unmerged paths. | |
176 | (fix conflicts and run "git commit") | |
b0a61ab2 | 177 | (use "git merge --abort" to abort the merge) |
1c7969c9 MM |
178 | |
179 | Unmerged paths: | |
180 | (use "git add/rm <file>..." as appropriate to mark resolution) | |
c7cb333f | 181 | both deleted: main.txt |
01dc8133 | 182 | added by them: sub_main.txt |
c7cb333f | 183 | added by us: sub_second.txt |
1c7969c9 MM |
184 | |
185 | no changes added to commit (use "git add" and/or "git commit -a") | |
186 | EOF | |
83c750ac | 187 | git status --untracked-files=no >actual && |
1108cea7 | 188 | test_cmp expected actual |
83c750ac LK |
189 | ' |
190 | ||
191 | ||
96b0ec1a LK |
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 && | |
01dc8133 | 195 | git add sub_main.txt && |
96b0ec1a | 196 | git add sub_second.txt && |
1c7969c9 MM |
197 | cat >expected <<\EOF && |
198 | On branch conflict_second | |
199 | You have unmerged paths. | |
200 | (fix conflicts and run "git commit") | |
b0a61ab2 | 201 | (use "git merge --abort" to abort the merge) |
1c7969c9 MM |
202 | |
203 | Changes to be committed: | |
01dc8133 | 204 | new file: sub_main.txt |
1c7969c9 MM |
205 | |
206 | Unmerged paths: | |
207 | (use "git rm <file>..." to mark resolution) | |
c7cb333f | 208 | both deleted: main.txt |
1c7969c9 MM |
209 | |
210 | Untracked files not listed (use -u option to show untracked files) | |
211 | EOF | |
96b0ec1a | 212 | git status --untracked-files=no >actual && |
1108cea7 | 213 | test_cmp expected actual && |
96b0ec1a | 214 | git reset --hard && |
01dc8133 | 215 | git checkout main |
96b0ec1a LK |
216 | ' |
217 | ||
baf0a3e4 | 218 | test_expect_success 'status --branch with detached HEAD' ' |
7ca8c189 | 219 | git reset --hard && |
01dc8133 | 220 | git checkout main^0 && |
7ca8c189 RS |
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 | |
1108cea7 | 230 | test_cmp expected actual |
7ca8c189 | 231 | ' |
96b0ec1a | 232 | |
c4f596b9 JH |
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 && | |
01dc8133 | 236 | git checkout main^0 && |
c4f596b9 JH |
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 | |
1108cea7 | 246 | test_cmp expected actual |
c4f596b9 JH |
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 | ||
29796c6c | 254 | test_done |