t5000: use check_mtime()
[git.git] / t / t7060-wtstatus.sh
blobaaeb4a533440df495d99e3b123f1640afe4374e7
1 #!/bin/sh
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
9 . ./test-lib.sh
11 test_expect_success setup '
12 git config --global advice.statusuoption false &&
13 test_commit A &&
14 test_commit B oneside added &&
15 git checkout A^0 &&
16 test_commit C oneside created
19 test_expect_success 'A/A conflict' '
20 git checkout B^0 &&
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' '
37 cat >expect <<EOF &&
38 On branch side
39 You have unmerged paths.
40 (fix conflicts and run "git commit")
41 (use "git merge --abort" to abort the merge)
43 Unmerged paths:
44 (use "git add/rm <file>..." as appropriate to mark resolution)
45 deleted by us: foo
47 no changes added to commit (use "git add" and/or "git commit -a")
48 EOF
49 mkdir mdconflict &&
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 &&
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' '
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" &&
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 &&
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
87 test_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
97 test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' '
98 cat >expected <<-EOF &&
99 U ONE
100 A THREE
101 A TWO
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 &&
109 U ONE
110 A THREE
111 A TWO
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 &&
119 U ONE
120 C ONE THREE
121 C ONE TWO
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)' '
130 git reset --hard &&
131 git checkout main &&
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 &&
137 git checkout main &&
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 &&
142 On branch main
143 You have unmerged paths.
144 (fix conflicts and run "git commit")
145 (use "git merge --abort" to abort the merge)
147 Unmerged paths:
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' '
160 git reset --hard &&
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)
180 Unmerged paths:
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
207 Unmerged paths:
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 &&
215 git reset --hard &&
216 git checkout main
219 test_expect_success 'status --branch with detached HEAD' '
220 git reset --hard &&
221 git checkout main^0 &&
222 git status --branch --porcelain >actual &&
223 cat >expected <<-EOF &&
224 ## HEAD (no branch)
225 ?? .gitconfig
226 ?? actual
227 ?? expect
228 ?? expected
229 ?? mdconflict/
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' '
236 git reset --hard &&
237 git checkout main^0 &&
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/
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
255 test_done