interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t7060-wtstatus.sh

253 lines · 6282 bytes Raw Blame History
1#!/bin/sh
2
3test_description='basic work tree status reporting'
4
5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 git config --global advice.statusuoption false &&
12 echo "/.gitconfig" >>.git/info/exclude &&
13 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
36test_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 merge --continue")
41 (use "git merge --abort" to abort the merge)
42
43Unmerged paths:
44 (use "git add/rm <file>..." as appropriate to mark resolution)
45 deleted by us: foo
46
47no changes added to commit (use "git add" and/or "git commit -a")
48EOF
49 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 &&
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
63 )
64'
65
66test_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
113 git diff-index --cached -M --name-status HEAD >actual &&
114 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
128
129test_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 &&
142On branch main
143You have unmerged paths.
144 (fix conflicts and run "git merge --continue")
145 (use "git merge --abort" to abort the merge)
146
147Unmerged paths:
148 (use "git add/rm <file>..." as appropriate to mark resolution)
149 both added: conflict.txt
150 deleted by them: main.txt
151
152no changes added to commit (use "git add" and/or "git commit -a")
153EOF
154 git status --untracked-files=no >actual &&
155 test_cmp expected actual
156'
157
158
159test_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"
169'
170
171
172test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
173 test_must_fail git merge conflict &&
174 cat >expected <<\EOF &&
175On branch conflict_second
176You have unmerged paths.
177 (fix conflicts and run "git merge --continue")
178 (use "git merge --abort" to abort the merge)
179
180Unmerged 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
185
186no changes added to commit (use "git add" and/or "git commit -a")
187EOF
188 git status --untracked-files=no >actual &&
189 test_cmp expected actual
190'
191
192
193test_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 &&
199On branch conflict_second
200You have unmerged paths.
201 (fix conflicts and run "git merge --continue")
202 (use "git merge --abort" to abort the merge)
203
204Changes to be committed:
205 new file: sub_main.txt
206
207Unmerged paths:
208 (use "git rm <file>..." to mark resolution)
209 both deleted: main.txt
210
211Untracked files not listed (use -u option to show untracked files)
212EOF
213 git status --untracked-files=no >actual &&
214 test_cmp expected actual &&
215 git reset --hard &&
216 git checkout main
217'
218
219test_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 ?? actual
226 ?? expect
227 ?? expected
228 ?? mdconflict/
229 EOF
230 test_cmp expected actual
231'
232
233## Duplicate the above test and verify --porcelain=v1 arg parsing.
234test_expect_success 'status --porcelain=v1 --branch with detached HEAD' '
235 git reset --hard &&
236 git checkout main^0 &&
237 git status --branch --porcelain=v1 >actual &&
238 cat >expected <<-EOF &&
239 ## HEAD (no branch)
240 ?? actual
241 ?? expect
242 ?? expected
243 ?? mdconflict/
244 EOF
245 test_cmp expected actual
246'
247
248## Verify parser error on invalid --porcelain argument.
249test_expect_success 'status --porcelain=bogus' '
250 test_must_fail git status --porcelain=bogus
251'
252
253test_done