3 test_description
='basic work tree status reporting'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 test_expect_success setup
'
12 git config --global advice.statusuoption false &&
14 test_commit B oneside added &&
16 test_commit C oneside created
19 test_expect_success
'A/A conflict' '
21 test_must_fail git merge C
24 test_expect_success
'Report path with conflict' '
25 git diff --cached --name-status >actual &&
26 echo "U oneside" >expect &&
27 test_cmp expect actual
30 test_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
36 test_expect_success
'M/D conflict does not segfault' '
39 You have unmerged paths.
40 (fix conflicts and run "git commit")
41 (use "git merge --abort" to abort the merge)
44 (use "git add/rm <file>..." as appropriate to mark resolution)
47 no changes added to commit (use "git add" and/or "git commit -a")
53 test_commit initial foo "" &&
54 test_commit modify foo foo &&
55 git checkout -b side HEAD^ &&
57 git commit -m delete &&
58 test_must_fail git merge main &&
59 test_must_fail git commit --dry-run >../actual &&
60 test_cmp ../expect ../actual &&
61 git status >../actual &&
62 test_cmp ../expect ../actual
66 test_expect_success
'rename & unmerged setup' '
68 cat "$TEST_DIRECTORY/README" >ONE &&
71 git commit -m "One commit with ONE" &&
77 sha1=$(git rev-parse :ONE) &&
78 git rm --cached ONE &&
80 echo "100644 $sha1 1 ONE" &&
81 echo "100644 $sha1 2 ONE" &&
82 echo "100644 $sha1 3 ONE"
83 ) | git update-index --index-info &&
87 test_expect_success
'rename & unmerged status' '
88 git status -suno >actual &&
94 test_cmp expect actual
97 test_expect_success
'git diff-index --cached shows 2 added + 1 unmerged' '
98 cat >expected <<-EOF &&
103 git diff-index --cached --name-status HEAD >actual &&
104 test_cmp expected actual
107 test_expect_success
'git diff-index --cached -M shows 2 added + 1 unmerged' '
108 cat >expected <<-EOF &&
113 git diff-index --cached -M --name-status HEAD >actual &&
114 test_cmp expected actual
117 test_expect_success
'git diff-index --cached -C shows 2 copies + 1 unmerged' '
118 cat >expected <<-EOF &&
123 git diff-index --cached -C --name-status HEAD |
124 sed "s/^C[0-9]*/C/g" >actual &&
125 test_cmp expected actual
129 test_expect_success
'status when conflicts with add and rm advice (deleted by them)' '
132 test_commit init main.txt init &&
133 git checkout -b second_branch &&
135 git commit -m "main.txt deleted on second_branch" &&
136 test_commit second conflict.txt second &&
138 test_commit on_second main.txt on_second &&
139 test_commit main conflict.txt main &&
140 test_must_fail git merge second_branch &&
141 cat >expected <<\EOF &&
143 You have unmerged paths.
144 (fix conflicts and run "git commit")
145 (use "git merge --abort" to abort the merge)
148 (use "git add/rm <file>..." as appropriate to mark resolution)
149 both added: conflict.txt
150 deleted by them: main.txt
152 no changes added to commit (use "git add" and/or "git commit -a")
154 git status --untracked-files=no >actual &&
155 test_cmp expected actual
159 test_expect_success
'prepare for conflicts' '
161 git checkout -b conflict &&
162 test_commit one main.txt one &&
163 git branch conflict_second &&
164 git mv main.txt sub_main.txt &&
165 git commit -m "main.txt renamed in sub_main.txt" &&
166 git checkout conflict_second &&
167 git mv main.txt sub_second.txt &&
168 git commit -m "main.txt renamed in sub_second.txt"
172 test_expect_success
'status when conflicts with add and rm advice (both deleted)' '
173 test_must_fail git merge conflict &&
174 cat >expected <<\EOF &&
175 On branch conflict_second
176 You have unmerged paths.
177 (fix conflicts and run "git commit")
178 (use "git merge --abort" to abort the merge)
181 (use "git add/rm <file>..." as appropriate to mark resolution)
182 both deleted: main.txt
183 added by them: sub_main.txt
184 added by us: sub_second.txt
186 no changes added to commit (use "git add" and/or "git commit -a")
188 git status --untracked-files=no >actual &&
189 test_cmp expected actual
193 test_expect_success
'status when conflicts with only rm advice (both deleted)' '
194 git reset --hard conflict_second &&
195 test_must_fail git merge conflict &&
196 git add sub_main.txt &&
197 git add sub_second.txt &&
198 cat >expected <<\EOF &&
199 On branch conflict_second
200 You have unmerged paths.
201 (fix conflicts and run "git commit")
202 (use "git merge --abort" to abort the merge)
204 Changes to be committed:
205 new file: sub_main.txt
208 (use "git rm <file>..." to mark resolution)
209 both deleted: main.txt
211 Untracked files not listed (use -u option to show untracked files)
213 git status --untracked-files=no >actual &&
214 test_cmp expected actual &&
219 test_expect_success
'status --branch with detached HEAD' '
221 git checkout main^0 &&
222 git status --branch --porcelain >actual &&
223 cat >expected <<-EOF &&
231 test_cmp expected actual
234 ## Duplicate the above test and verify --porcelain=v1 arg parsing.
235 test_expect_success
'status --porcelain=v1 --branch with detached HEAD' '
237 git checkout main^0 &&
238 git status --branch --porcelain=v1 >actual &&
239 cat >expected <<-EOF &&
247 test_cmp expected actual
250 ## Verify parser error on invalid --porcelain argument.
251 test_expect_success
'status --porcelain=bogus' '
252 test_must_fail git status --porcelain=bogus