5ecafac99bacfb2f6f7527f2bf7989b52cc8d07b
1#!/bin/sh
2
3test_description='basic work tree status reporting'
4
5. ./test-lib.sh
6
7test_expect_success 'use status.displayCommentPrefix by default ' '
8 git config --global status.displayCommentPrefix true
9'
10
11test_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
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
36cat >expect <<EOF
37# On branch side
38# You have unmerged paths.
39# (fix conflicts and run "git commit")
40#
41# Unmerged paths:
42# (use "git add/rm <file>..." as appropriate to mark resolution)
43#
44# deleted by us: foo
45#
46no changes added to commit (use "git add" and/or "git commit -a")
47EOF
48
49test_expect_success 'M/D conflict does not segfault' '
50 mkdir mdconflict &&
51 (
52 cd mdconflict &&
53 git init &&
54 test_commit initial foo "" &&
55 test_commit modify foo foo &&
56 git checkout -b side HEAD^ &&
57 git rm foo &&
58 git commit -m delete &&
59 test_must_fail git merge master &&
60 test_must_fail git commit --dry-run >../actual &&
61 test_i18ncmp ../expect ../actual &&
62 git status >../actual &&
63 test_i18ncmp ../expect ../actual
64 )
65'
66
67test_expect_success 'rename & unmerged setup' '
68 git rm -f -r . &&
69 cat "$TEST_DIRECTORY/README" >ONE &&
70 git add ONE &&
71 test_tick &&
72 git commit -m "One commit with ONE" &&
73
74 echo Modified >TWO &&
75 cat ONE >>TWO &&
76 cat ONE >>THREE &&
77 git add TWO THREE &&
78 sha1=$(git rev-parse :ONE) &&
79 git rm --cached ONE &&
80 (
81 echo "100644 $sha1 1 ONE" &&
82 echo "100644 $sha1 2 ONE" &&
83 echo "100644 $sha1 3 ONE"
84 ) | git update-index --index-info &&
85 echo Further >>THREE
86'
87
88test_expect_success 'rename & unmerged status' '
89 git status -suno >actual &&
90 cat >expect <<-EOF &&
91 UU ONE
92 AM THREE
93 A TWO
94 EOF
95 test_cmp expect actual
96'
97
98test_expect_success 'git diff-index --cached shows 2 added + 1 unmerged' '
99 cat >expected <<-EOF &&
100 U ONE
101 A THREE
102 A TWO
103 EOF
104 git diff-index --cached --name-status HEAD >actual &&
105 test_cmp expected actual
106'
107
108test_expect_success 'git diff-index --cached -M shows 2 added + 1 unmerged' '
109 cat >expected <<-EOF &&
110 U ONE
111 A THREE
112 A TWO
113 EOF
114 git diff-index --cached --name-status HEAD >actual &&
115 test_cmp expected actual
116'
117
118test_expect_success 'git diff-index --cached -C shows 2 copies + 1 unmerged' '
119 cat >expected <<-EOF &&
120 U ONE
121 C ONE THREE
122 C ONE TWO
123 EOF
124 git diff-index --cached -C --name-status HEAD |
125 sed "s/^C[0-9]*/C/g" >actual &&
126 test_cmp expected actual
127'
128
129
130test_expect_success 'status when conflicts with add and rm advice (deleted by them)' '
131 git reset --hard &&
132 git checkout master &&
133 test_commit init main.txt init &&
134 git checkout -b second_branch &&
135 git rm main.txt &&
136 git commit -m "main.txt deleted on second_branch" &&
137 test_commit second conflict.txt second &&
138 git checkout master &&
139 test_commit on_second main.txt on_second &&
140 test_commit master conflict.txt master &&
141 test_must_fail git merge second_branch &&
142 cat >expected <<-\EOF &&
143 # On branch master
144 # You have unmerged paths.
145 # (fix conflicts and run "git commit")
146 #
147 # Unmerged paths:
148 # (use "git add/rm <file>..." as appropriate to mark resolution)
149 #
150 # both added: conflict.txt
151 # deleted by them: main.txt
152 #
153 no changes added to commit (use "git add" and/or "git commit -a")
154 EOF
155 git status --untracked-files=no >actual &&
156 test_i18ncmp expected actual
157'
158
159
160test_expect_success 'prepare for conflicts' '
161 git reset --hard &&
162 git checkout -b conflict &&
163 test_commit one main.txt one &&
164 git branch conflict_second &&
165 git mv main.txt sub_master.txt &&
166 git commit -m "main.txt renamed in sub_master.txt" &&
167 git checkout conflict_second &&
168 git mv main.txt sub_second.txt &&
169 git commit -m "main.txt renamed in sub_second.txt"
170'
171
172
173test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
174 test_must_fail git merge conflict &&
175 cat >expected <<-\EOF &&
176 # On branch conflict_second
177 # You have unmerged paths.
178 # (fix conflicts and run "git commit")
179 #
180 # Unmerged paths:
181 # (use "git add/rm <file>..." as appropriate to mark resolution)
182 #
183 # both deleted: main.txt
184 # added by them: sub_master.txt
185 # added by us: sub_second.txt
186 #
187 no changes added to commit (use "git add" and/or "git commit -a")
188 EOF
189 git status --untracked-files=no >actual &&
190 test_i18ncmp expected actual
191'
192
193
194test_expect_success 'status when conflicts with only rm advice (both deleted)' '
195 git reset --hard conflict_second &&
196 test_must_fail git merge conflict &&
197 git add sub_master.txt &&
198 git add sub_second.txt &&
199 cat >expected <<-\EOF &&
200 # On branch conflict_second
201 # You have unmerged paths.
202 # (fix conflicts and run "git commit")
203 #
204 # Changes to be committed:
205 #
206 # new file: sub_master.txt
207 #
208 # Unmerged paths:
209 # (use "git rm <file>..." to mark resolution)
210 #
211 # both deleted: main.txt
212 #
213 # Untracked files not listed (use -u option to show untracked files)
214 EOF
215 git status --untracked-files=no >actual &&
216 test_i18ncmp expected actual &&
217 git reset --hard &&
218 git checkout master
219'
220
221
222test_done