blob: aaeb4a533440df495d99e3b123f1640afe4374e7 [file] [log] [blame]
Junio C Hamano29796c62009-08-04 16:25:40 -07001#!/bin/sh
2
3test_description='basic work tree status reporting'
4
Johannes Schindelin01dc8132020-11-18 23:44:39 +00005GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00006export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
Ævar Arnfjörð Bjarmason3e3b9322022-07-28 01:13:41 +02008TEST_PASSES_SANITIZE_LEAK=true
Junio C Hamano29796c62009-08-04 16:25:40 -07009. ./test-lib.sh
10
11test_expect_success setup '
Nguyễn Thái Ngọc Duy6a38ef22013-03-13 19:59:16 +070012 git config --global advice.statusuoption false &&
Junio C Hamano29796c62009-08-04 16:25:40 -070013 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
Matthieu Moy1c7969c2013-09-06 19:43:08 +020036test_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")
Matthieu Moyb0a61ab2016-07-21 14:58:37 +020041 (use "git merge --abort" to abort the merge)
Matthieu Moy1c7969c2013-09-06 19:43:08 +020042
43Unmerged paths:
44 (use "git add/rm <file>..." as appropriate to mark resolution)
Junio C Hamanoc7cb3332014-03-12 13:43:51 -070045 deleted by us: foo
Matthieu Moy1c7969c2013-09-06 19:43:08 +020046
Junio C Hamano4d4d5722009-08-05 00:04:51 -070047no changes added to commit (use "git add" and/or "git commit -a")
48EOF
Junio C Hamano4d4d5722009-08-05 00:04:51 -070049 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 &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +000058 test_must_fail git merge main &&
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -070059 test_must_fail git commit --dry-run >../actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010060 test_cmp ../expect ../actual &&
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -070061 git status >../actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +010062 test_cmp ../expect ../actual
Junio C Hamano9e4b7ab2009-08-15 02:27:39 -070063 )
Junio C Hamano4d4d5722009-08-05 00:04:51 -070064'
65
Martin von Zweigbergkd7c9bf22011-03-23 22:41:01 -040066test_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
Matthieu Pratb894d3e2015-09-02 14:12:55 -0400113 git diff-index --cached -M --name-status HEAD >actual &&
Martin von Zweigbergkd7c9bf22011-03-23 22:41:01 -0400114 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
Lucien Kong83c750a2012-06-05 22:21:24 +0200128
129test_expect_success 'status when conflicts with add and rm advice (deleted by them)' '
130 git reset --hard &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000131 git checkout main &&
Lucien Kong83c750a2012-06-05 22:21:24 +0200132 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 &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000137 git checkout main &&
Lucien Kong83c750a2012-06-05 22:21:24 +0200138 test_commit on_second main.txt on_second &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000139 test_commit main conflict.txt main &&
Lucien Kong83c750a2012-06-05 22:21:24 +0200140 test_must_fail git merge second_branch &&
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200141 cat >expected <<\EOF &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000142On branch main
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200143You have unmerged paths.
144 (fix conflicts and run "git commit")
Matthieu Moyb0a61ab2016-07-21 14:58:37 +0200145 (use "git merge --abort" to abort the merge)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200146
147Unmerged paths:
148 (use "git add/rm <file>..." as appropriate to mark resolution)
Junio C Hamanoc7cb3332014-03-12 13:43:51 -0700149 both added: conflict.txt
150 deleted by them: main.txt
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200151
152no changes added to commit (use "git add" and/or "git commit -a")
153EOF
Lucien Kong83c750a2012-06-05 22:21:24 +0200154 git status --untracked-files=no >actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100155 test_cmp expected actual
Lucien Kong83c750a2012-06-05 22:21:24 +0200156'
157
158
Lucien Kong96b0ec12012-06-05 22:21:26 +0200159test_expect_success 'prepare for conflicts' '
Lucien Kong83c750a2012-06-05 22:21:24 +0200160 git reset --hard &&
161 git checkout -b conflict &&
162 test_commit one main.txt one &&
163 git branch conflict_second &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000164 git mv main.txt sub_main.txt &&
165 git commit -m "main.txt renamed in sub_main.txt" &&
Lucien Kong83c750a2012-06-05 22:21:24 +0200166 git checkout conflict_second &&
167 git mv main.txt sub_second.txt &&
Lucien Kong96b0ec12012-06-05 22:21:26 +0200168 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)' '
Lucien Kong83c750a2012-06-05 22:21:24 +0200173 test_must_fail git merge conflict &&
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200174 cat >expected <<\EOF &&
175On branch conflict_second
176You have unmerged paths.
177 (fix conflicts and run "git commit")
Matthieu Moyb0a61ab2016-07-21 14:58:37 +0200178 (use "git merge --abort" to abort the merge)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200179
180Unmerged paths:
181 (use "git add/rm <file>..." as appropriate to mark resolution)
Junio C Hamanoc7cb3332014-03-12 13:43:51 -0700182 both deleted: main.txt
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000183 added by them: sub_main.txt
Junio C Hamanoc7cb3332014-03-12 13:43:51 -0700184 added by us: sub_second.txt
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200185
186no changes added to commit (use "git add" and/or "git commit -a")
187EOF
Lucien Kong83c750a2012-06-05 22:21:24 +0200188 git status --untracked-files=no >actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100189 test_cmp expected actual
Lucien Kong83c750a2012-06-05 22:21:24 +0200190'
191
192
Lucien Kong96b0ec12012-06-05 22:21:26 +0200193test_expect_success 'status when conflicts with only rm advice (both deleted)' '
194 git reset --hard conflict_second &&
195 test_must_fail git merge conflict &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000196 git add sub_main.txt &&
Lucien Kong96b0ec12012-06-05 22:21:26 +0200197 git add sub_second.txt &&
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200198 cat >expected <<\EOF &&
199On branch conflict_second
200You have unmerged paths.
201 (fix conflicts and run "git commit")
Matthieu Moyb0a61ab2016-07-21 14:58:37 +0200202 (use "git merge --abort" to abort the merge)
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200203
204Changes to be committed:
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000205 new file: sub_main.txt
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200206
207Unmerged paths:
208 (use "git rm <file>..." to mark resolution)
Junio C Hamanoc7cb3332014-03-12 13:43:51 -0700209 both deleted: main.txt
Matthieu Moy1c7969c2013-09-06 19:43:08 +0200210
211Untracked files not listed (use -u option to show untracked files)
212EOF
Lucien Kong96b0ec12012-06-05 22:21:26 +0200213 git status --untracked-files=no >actual &&
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100214 test_cmp expected actual &&
Lucien Kong96b0ec12012-06-05 22:21:26 +0200215 git reset --hard &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000216 git checkout main
Lucien Kong96b0ec12012-06-05 22:21:26 +0200217'
218
René Scharfebaf0a3e2015-10-31 18:36:35 +0100219test_expect_success 'status --branch with detached HEAD' '
René Scharfe7ca8c182015-10-31 18:35:32 +0100220 git reset --hard &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000221 git checkout main^0 &&
René Scharfe7ca8c182015-10-31 18:35:32 +0100222 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
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100231 test_cmp expected actual
René Scharfe7ca8c182015-10-31 18:35:32 +0100232'
Lucien Kong96b0ec12012-06-05 22:21:26 +0200233
Jeff Hostetlerc4f596b2016-08-05 18:00:28 -0400234## Duplicate the above test and verify --porcelain=v1 arg parsing.
235test_expect_success 'status --porcelain=v1 --branch with detached HEAD' '
236 git reset --hard &&
Johannes Schindelin01dc8132020-11-18 23:44:39 +0000237 git checkout main^0 &&
Jeff Hostetlerc4f596b2016-08-05 18:00:28 -0400238 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
Ævar Arnfjörð Bjarmason1108cea2021-02-11 02:53:53 +0100247 test_cmp expected actual
Jeff Hostetlerc4f596b2016-08-05 18:00:28 -0400248'
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
Junio C Hamano29796c62009-08-04 16:25:40 -0700255test_done