3 test_description
='basic work tree status reporting'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success setup
'
11 git config --global advice.statusuoption false &&
13 test_commit B oneside added &&
15 test_commit C oneside created
18 test_expect_success
'A/A conflict' '
20 test_must_fail git merge C
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
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
35 test_expect_success
'M/D conflict does not segfault' '
38 You have unmerged paths.
39 (fix conflicts and run "git commit")
40 (use "git merge --abort" to abort the merge)
43 (use "git add/rm <file>..." as appropriate to mark resolution)
46 no changes added to commit (use "git add" and/or "git commit -a")
52 test_commit initial foo "" &&
53 test_commit modify foo foo &&
54 git checkout -b side HEAD^ &&
56 git commit -m delete &&
57 test_must_fail git merge main &&
58 test_must_fail git commit --dry-run >../actual &&
59 test_cmp ../expect ../actual &&
60 git status >../actual &&
61 test_cmp ../expect ../actual
65 test_expect_success
'rename & unmerged setup' '
67 cat "$TEST_DIRECTORY/README" >ONE &&
70 git commit -m "One commit with ONE" &&
76 sha1=$(git rev-parse :ONE) &&
77 git rm --cached ONE &&
79 echo "100644 $sha1 1 ONE" &&
80 echo "100644 $sha1 2 ONE" &&
81 echo "100644 $sha1 3 ONE"
82 ) | git update-index --index-info &&
86 test_expect_success
'rename & unmerged status' '
87 git status -suno >actual &&
93 test_cmp expect actual
96 test_expect_success
'git diff-index --cached shows 2 added + 1 unmerged' '
97 cat >expected <<-EOF &&
102 git diff-index --cached --name-status HEAD >actual &&
103 test_cmp expected actual
106 test_expect_success
'git diff-index --cached -M shows 2 added + 1 unmerged' '
107 cat >expected <<-EOF &&
112 git diff-index --cached -M --name-status HEAD >actual &&
113 test_cmp expected actual
116 test_expect_success
'git diff-index --cached -C shows 2 copies + 1 unmerged' '
117 cat >expected <<-EOF &&
122 git diff-index --cached -C --name-status HEAD |
123 sed "s/^C[0-9]*/C/g" >actual &&
124 test_cmp expected actual
128 test_expect_success
'status when conflicts with add and rm advice (deleted by them)' '
131 test_commit init main.txt init &&
132 git checkout -b second_branch &&
134 git commit -m "main.txt deleted on second_branch" &&
135 test_commit second conflict.txt second &&
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 &&
142 You have unmerged paths.
143 (fix conflicts and run "git commit")
144 (use "git merge --abort" to abort the merge)
147 (use "git add/rm <file>..." as appropriate to mark resolution)
148 both added: conflict.txt
149 deleted by them: main.txt
151 no changes added to commit (use "git add" and/or "git commit -a")
153 git status --untracked-files=no >actual &&
154 test_cmp expected actual
158 test_expect_success
'prepare for conflicts' '
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"
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)
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
185 no changes added to commit (use "git add" and/or "git commit -a")
187 git status --untracked-files=no >actual &&
188 test_cmp expected actual
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)
203 Changes to be committed:
204 new file: sub_main.txt
207 (use "git rm <file>..." to mark resolution)
208 both deleted: main.txt
210 Untracked files not listed (use -u option to show untracked files)
212 git status --untracked-files=no >actual &&
213 test_cmp expected actual &&
218 test_expect_success
'status --branch with detached HEAD' '
220 git checkout main^0 &&
221 git status --branch --porcelain >actual &&
222 cat >expected <<-EOF &&
230 test_cmp expected actual
233 ## Duplicate the above test and verify --porcelain=v1 arg parsing.
234 test_expect_success
'status --porcelain=v1 --branch with detached HEAD' '
236 git checkout main^0 &&
237 git status --branch --porcelain=v1 >actual &&
238 cat >expected <<-EOF &&
246 test_cmp expected actual
249 ## Verify parser error on invalid --porcelain argument.
250 test_expect_success
'status --porcelain=bogus' '
251 test_must_fail git status --porcelain=bogus