1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
6 test_description='git-status'
8 . ./test-lib.sh
10 test_expect_success 'setup' '
11 : > tracked &&
12 : > modified &&
13 mkdir dir1 &&
14 : > dir1/tracked &&
15 : > dir1/modified &&
16 mkdir dir2 &&
17 : > dir1/tracked &&
18 : > dir1/modified &&
19 git add . &&
21 git status >output &&
23 test_tick &&
24 git commit -m initial &&
25 : > untracked &&
26 : > dir1/untracked &&
27 : > dir2/untracked &&
28 echo 1 > dir1/modified &&
29 echo 2 > dir2/modified &&
30 echo 3 > dir2/added &&
31 git add dir2/added
32 '
34 test_expect_success 'status (1)' '
36 grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
38 '
40 cat > expect << \EOF
41 # On branch master
42 # Changes to be committed:
43 # (use "git reset HEAD <file>..." to unstage)
44 #
45 # new file: dir2/added
46 #
47 # Changed but not updated:
48 # (use "git add <file>..." to update what will be committed)
49 #
50 # modified: dir1/modified
51 #
52 # Untracked files:
53 # (use "git add <file>..." to include in what will be committed)
54 #
55 # dir1/untracked
56 # dir2/modified
57 # dir2/untracked
58 # expect
59 # output
60 # untracked
61 EOF
63 test_expect_success 'status (2)' '
65 git status > output &&
66 test_cmp expect output
68 '
70 cat >expect <<EOF
71 # On branch master
72 # Changes to be committed:
73 # (use "git reset HEAD <file>..." to unstage)
74 #
75 # new file: dir2/added
76 #
77 # Changed but not updated:
78 # (use "git add <file>..." to update what will be committed)
79 #
80 # modified: dir1/modified
81 #
82 # Untracked files not listed (use -u option to show untracked files)
83 EOF
84 test_expect_success 'status -uno' '
85 mkdir dir3 &&
86 : > dir3/untracked1 &&
87 : > dir3/untracked2 &&
88 git status -uno >output &&
89 test_cmp expect output
90 '
92 cat >expect <<EOF
93 # On branch master
94 # Changes to be committed:
95 # (use "git reset HEAD <file>..." to unstage)
96 #
97 # new file: dir2/added
98 #
99 # Changed but not updated:
100 # (use "git add <file>..." to update what will be committed)
101 #
102 # modified: dir1/modified
103 #
104 # Untracked files:
105 # (use "git add <file>..." to include in what will be committed)
106 #
107 # dir1/untracked
108 # dir2/modified
109 # dir2/untracked
110 # dir3/
111 # expect
112 # output
113 # untracked
114 EOF
115 test_expect_success 'status -unormal' '
116 git status -unormal >output &&
117 test_cmp expect output
118 '
120 cat >expect <<EOF
121 # On branch master
122 # Changes to be committed:
123 # (use "git reset HEAD <file>..." to unstage)
124 #
125 # new file: dir2/added
126 #
127 # Changed but not updated:
128 # (use "git add <file>..." to update what will be committed)
129 #
130 # modified: dir1/modified
131 #
132 # Untracked files:
133 # (use "git add <file>..." to include in what will be committed)
134 #
135 # dir1/untracked
136 # dir2/modified
137 # dir2/untracked
138 # dir3/untracked1
139 # dir3/untracked2
140 # expect
141 # output
142 # untracked
143 EOF
144 test_expect_success 'status -uall' '
145 git status -uall >output &&
146 rm -rf dir3 &&
147 test_cmp expect output
148 '
150 cat > expect << \EOF
151 # On branch master
152 # Changes to be committed:
153 # (use "git reset HEAD <file>..." to unstage)
154 #
155 # new file: ../dir2/added
156 #
157 # Changed but not updated:
158 # (use "git add <file>..." to update what will be committed)
159 #
160 # modified: modified
161 #
162 # Untracked files:
163 # (use "git add <file>..." to include in what will be committed)
164 #
165 # untracked
166 # ../dir2/modified
167 # ../dir2/untracked
168 # ../expect
169 # ../output
170 # ../untracked
171 EOF
173 test_expect_success 'status with relative paths' '
175 (cd dir1 && git status) > output &&
176 test_cmp expect output
178 '
180 cat > expect << \EOF
181 # On branch master
182 # Changes to be committed:
183 # (use "git reset HEAD <file>..." to unstage)
184 #
185 # new file: dir2/added
186 #
187 # Changed but not updated:
188 # (use "git add <file>..." to update what will be committed)
189 #
190 # modified: dir1/modified
191 #
192 # Untracked files:
193 # (use "git add <file>..." to include in what will be committed)
194 #
195 # dir1/untracked
196 # dir2/modified
197 # dir2/untracked
198 # expect
199 # output
200 # untracked
201 EOF
203 test_expect_success 'status without relative paths' '
205 git config status.relativePaths false
206 (cd dir1 && git status) > output &&
207 test_cmp expect output
209 '
211 cat <<EOF >expect
212 # On branch master
213 # Changes to be committed:
214 # (use "git reset HEAD <file>..." to unstage)
215 #
216 # modified: dir1/modified
217 #
218 # Untracked files:
219 # (use "git add <file>..." to include in what will be committed)
220 #
221 # dir1/untracked
222 # dir2/
223 # expect
224 # output
225 # untracked
226 EOF
227 test_expect_success 'status of partial commit excluding new file in index' '
228 git status dir1/modified >output &&
229 test_cmp expect output
230 '
232 test_expect_success 'setup status submodule summary' '
233 test_create_repo sm && (
234 cd sm &&
235 >foo &&
236 git add foo &&
237 git commit -m "Add foo"
238 ) &&
239 git add sm
240 '
242 cat >expect <<EOF
243 # On branch master
244 # Changes to be committed:
245 # (use "git reset HEAD <file>..." to unstage)
246 #
247 # new file: dir2/added
248 # new file: sm
249 #
250 # Changed but not updated:
251 # (use "git add <file>..." to update what will be committed)
252 #
253 # modified: dir1/modified
254 #
255 # Untracked files:
256 # (use "git add <file>..." to include in what will be committed)
257 #
258 # dir1/untracked
259 # dir2/modified
260 # dir2/untracked
261 # expect
262 # output
263 # untracked
264 EOF
265 test_expect_success 'status submodule summary is disabled by default' '
266 git status >output &&
267 test_cmp expect output
268 '
270 head=$(cd sm && git rev-parse --short=7 --verify HEAD)
272 cat >expect <<EOF
273 # On branch master
274 # Changes to be committed:
275 # (use "git reset HEAD <file>..." to unstage)
276 #
277 # new file: dir2/added
278 # new file: sm
279 #
280 # Changed but not updated:
281 # (use "git add <file>..." to update what will be committed)
282 #
283 # modified: dir1/modified
284 #
285 # Modified submodules:
286 #
287 # * sm 0000000...$head (1):
288 # > Add foo
289 #
290 # Untracked files:
291 # (use "git add <file>..." to include in what will be committed)
292 #
293 # dir1/untracked
294 # dir2/modified
295 # dir2/untracked
296 # expect
297 # output
298 # untracked
299 EOF
300 test_expect_success 'status submodule summary' '
301 git config status.submodulesummary 10 &&
302 git status >output &&
303 test_cmp expect output
304 '
307 cat >expect <<EOF
308 # On branch master
309 # Changed but not updated:
310 # (use "git add <file>..." to update what will be committed)
311 #
312 # modified: dir1/modified
313 #
314 # Untracked files:
315 # (use "git add <file>..." to include in what will be committed)
316 #
317 # dir1/untracked
318 # dir2/modified
319 # dir2/untracked
320 # expect
321 # output
322 # untracked
323 no changes added to commit (use "git add" and/or "git commit -a")
324 EOF
325 test_expect_success 'status submodule summary (clean submodule)' '
326 git commit -m "commit submodule" &&
327 git config status.submodulesummary 10 &&
328 test_must_fail git status >output &&
329 test_cmp expect output
330 '
332 cat >expect <<EOF
333 # On branch master
334 # Changes to be committed:
335 # (use "git reset HEAD^1 <file>..." to unstage)
336 #
337 # new file: dir2/added
338 # new file: sm
339 #
340 # Changed but not updated:
341 # (use "git add <file>..." to update what will be committed)
342 #
343 # modified: dir1/modified
344 #
345 # Modified submodules:
346 #
347 # * sm 0000000...$head (1):
348 # > Add foo
349 #
350 # Untracked files:
351 # (use "git add <file>..." to include in what will be committed)
352 #
353 # dir1/untracked
354 # dir2/modified
355 # dir2/untracked
356 # expect
357 # output
358 # untracked
359 EOF
360 test_expect_success 'status submodule summary (--amend)' '
361 git config status.submodulesummary 10 &&
362 git status --amend >output &&
363 test_cmp expect output
364 '
366 test_done