]>
Commit | Line | Data |
---|---|---|
963c0407 SG |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2012 SZEDER Gábor | |
4 | # | |
5 | ||
6 | test_description='test git-specific bash prompt functions' | |
7 | ||
8 | . ./lib-bash.sh | |
9 | ||
af31a456 | 10 | . "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" |
963c0407 SG |
11 | |
12 | actual="$TRASH_DIRECTORY/actual" | |
1572e18e EA |
13 | c_red='\\[\\e[31m\\]' |
14 | c_green='\\[\\e[32m\\]' | |
15 | c_lblue='\\[\\e[1;34m\\]' | |
16 | c_clear='\\[\\e[0m\\]' | |
963c0407 SG |
17 | |
18 | test_expect_success 'setup for prompt tests' ' | |
963c0407 | 19 | git init otherrepo && |
4fe00b4f | 20 | echo 1 >file && |
963c0407 SG |
21 | git add file && |
22 | test_tick && | |
23 | git commit -m initial && | |
24 | git tag -a -m msg1 t1 && | |
25 | git checkout -b b1 && | |
4fe00b4f | 26 | echo 2 >file && |
963c0407 | 27 | git commit -m "second b1" file && |
4fe00b4f | 28 | echo 3 >file && |
963c0407 SG |
29 | git commit -m "third b1" file && |
30 | git tag -a -m msg2 t2 && | |
31 | git checkout -b b2 master && | |
4fe00b4f | 32 | echo 0 >file && |
963c0407 | 33 | git commit -m "second b2" file && |
4fe00b4f | 34 | echo 00 >file && |
b71dc3e1 | 35 | git commit -m "another b2" file && |
4fe00b4f | 36 | echo 000 >file && |
b71dc3e1 | 37 | git commit -m "yet another b2" file && |
0120b8c8 JA |
38 | mkdir ignored_dir && |
39 | echo "ignored_dir/" >>.gitignore && | |
963c0407 SG |
40 | git checkout master |
41 | ' | |
42 | ||
963c0407 | 43 | test_expect_success 'prompt - branch name' ' |
4fe00b4f SG |
44 | printf " (master)" >expected && |
45 | __git_ps1 >"$actual" && | |
963c0407 SG |
46 | test_cmp expected "$actual" |
47 | ' | |
48 | ||
868dc1ac SG |
49 | test_expect_success SYMLINKS 'prompt - branch name - symlink symref' ' |
50 | printf " (master)" >expected && | |
51 | test_when_finished "git checkout master" && | |
52 | test_config core.preferSymlinkRefs true && | |
53 | git checkout master && | |
54 | __git_ps1 >"$actual" && | |
55 | test_cmp expected "$actual" | |
56 | ' | |
57 | ||
e3e0b937 SG |
58 | test_expect_success 'prompt - unborn branch' ' |
59 | printf " (unborn)" >expected && | |
60 | git checkout --orphan unborn && | |
61 | test_when_finished "git checkout master" && | |
62 | __git_ps1 >"$actual" && | |
63 | test_cmp expected "$actual" | |
64 | ' | |
65 | ||
6ec63305 | 66 | if test_have_prereq !FUNNYNAMES; then |
a4889e64 SG |
67 | say 'Your filesystem does not allow newlines in filenames.' |
68 | fi | |
69 | ||
70 | test_expect_success FUNNYNAMES 'prompt - with newline in path' ' | |
6ec63305 WC |
71 | repo_with_newline="repo |
72 | with | |
73 | newline" && | |
74 | mkdir "$repo_with_newline" && | |
a4889e64 SG |
75 | printf " (master)" >expected && |
76 | git init "$repo_with_newline" && | |
77 | test_when_finished "rm -rf \"$repo_with_newline\"" && | |
78 | mkdir "$repo_with_newline"/subdir && | |
79 | ( | |
80 | cd "$repo_with_newline/subdir" && | |
81 | __git_ps1 >"$actual" | |
82 | ) && | |
83 | test_cmp expected "$actual" | |
84 | ' | |
85 | ||
963c0407 | 86 | test_expect_success 'prompt - detached head' ' |
e8f21caf SG |
87 | printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected && |
88 | test_config core.abbrev 13 && | |
963c0407 SG |
89 | git checkout b1^ && |
90 | test_when_finished "git checkout master" && | |
4fe00b4f | 91 | __git_ps1 >"$actual" && |
963c0407 SG |
92 | test_cmp expected "$actual" |
93 | ' | |
94 | ||
95 | test_expect_success 'prompt - describe detached head - contains' ' | |
4fe00b4f | 96 | printf " ((t2~1))" >expected && |
963c0407 SG |
97 | git checkout b1^ && |
98 | test_when_finished "git checkout master" && | |
99 | ( | |
100 | GIT_PS1_DESCRIBE_STYLE=contains && | |
4fe00b4f | 101 | __git_ps1 >"$actual" |
963c0407 SG |
102 | ) && |
103 | test_cmp expected "$actual" | |
104 | ' | |
105 | ||
106 | test_expect_success 'prompt - describe detached head - branch' ' | |
75504248 | 107 | printf " ((tags/t2~1))" >expected && |
963c0407 SG |
108 | git checkout b1^ && |
109 | test_when_finished "git checkout master" && | |
110 | ( | |
111 | GIT_PS1_DESCRIBE_STYLE=branch && | |
4fe00b4f | 112 | __git_ps1 >"$actual" |
963c0407 SG |
113 | ) && |
114 | test_cmp expected "$actual" | |
115 | ' | |
116 | ||
117 | test_expect_success 'prompt - describe detached head - describe' ' | |
4fe00b4f | 118 | printf " ((t1-1-g%s))" $(git log -1 --format="%h" b1^) >expected && |
963c0407 SG |
119 | git checkout b1^ && |
120 | test_when_finished "git checkout master" && | |
121 | ( | |
122 | GIT_PS1_DESCRIBE_STYLE=describe && | |
4fe00b4f | 123 | __git_ps1 >"$actual" |
963c0407 SG |
124 | ) && |
125 | test_cmp expected "$actual" | |
126 | ' | |
127 | ||
128 | test_expect_success 'prompt - describe detached head - default' ' | |
4fe00b4f | 129 | printf " ((t2))" >expected && |
963c0407 SG |
130 | git checkout --detach b1 && |
131 | test_when_finished "git checkout master" && | |
4fe00b4f | 132 | __git_ps1 >"$actual" && |
963c0407 SG |
133 | test_cmp expected "$actual" |
134 | ' | |
135 | ||
136 | test_expect_success 'prompt - inside .git directory' ' | |
4fe00b4f | 137 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
138 | ( |
139 | cd .git && | |
4fe00b4f | 140 | __git_ps1 >"$actual" |
963c0407 SG |
141 | ) && |
142 | test_cmp expected "$actual" | |
143 | ' | |
144 | ||
145 | test_expect_success 'prompt - deep inside .git directory' ' | |
4fe00b4f | 146 | printf " (GIT_DIR!)" >expected && |
963c0407 | 147 | ( |
5340d471 | 148 | cd .git/objects && |
4fe00b4f | 149 | __git_ps1 >"$actual" |
963c0407 SG |
150 | ) && |
151 | test_cmp expected "$actual" | |
152 | ' | |
153 | ||
154 | test_expect_success 'prompt - inside bare repository' ' | |
4fe00b4f | 155 | printf " (BARE:master)" >expected && |
963c0407 SG |
156 | git init --bare bare.git && |
157 | test_when_finished "rm -rf bare.git" && | |
158 | ( | |
159 | cd bare.git && | |
4fe00b4f | 160 | __git_ps1 >"$actual" |
963c0407 SG |
161 | ) && |
162 | test_cmp expected "$actual" | |
163 | ' | |
164 | ||
165 | test_expect_success 'prompt - interactive rebase' ' | |
6d04ce75 | 166 | printf " (b1|REBASE 2/3)" >expected && |
7412290c SG |
167 | write_script fake_editor.sh <<-\EOF && |
168 | echo "exec echo" >"$1" | |
169 | echo "edit $(git log -1 --format="%h")" >>"$1" | |
170 | echo "exec echo" >>"$1" | |
171 | EOF | |
963c0407 | 172 | test_when_finished "rm -f fake_editor.sh" && |
963c0407 SG |
173 | test_set_editor "$TRASH_DIRECTORY/fake_editor.sh" && |
174 | git checkout b1 && | |
175 | test_when_finished "git checkout master" && | |
176 | git rebase -i HEAD^ && | |
c00bfc9d | 177 | test_when_finished "git rebase --abort" && |
4fe00b4f | 178 | __git_ps1 >"$actual" && |
963c0407 SG |
179 | test_cmp expected "$actual" |
180 | ' | |
181 | ||
182 | test_expect_success 'prompt - rebase merge' ' | |
6d04ce75 | 183 | printf " (b2|REBASE 1/3)" >expected && |
963c0407 SG |
184 | git checkout b2 && |
185 | test_when_finished "git checkout master" && | |
186 | test_must_fail git rebase --merge b1 b2 && | |
187 | test_when_finished "git rebase --abort" && | |
4fe00b4f | 188 | __git_ps1 >"$actual" && |
963c0407 SG |
189 | test_cmp expected "$actual" |
190 | ' | |
191 | ||
6d04ce75 | 192 | test_expect_success 'prompt - rebase am' ' |
4fe00b4f | 193 | printf " (b2|REBASE 1/3)" >expected && |
963c0407 SG |
194 | git checkout b2 && |
195 | test_when_finished "git checkout master" && | |
10cdb9f3 | 196 | test_must_fail git rebase --apply b1 b2 && |
963c0407 | 197 | test_when_finished "git rebase --abort" && |
4fe00b4f | 198 | __git_ps1 >"$actual" && |
963c0407 SG |
199 | test_cmp expected "$actual" |
200 | ' | |
201 | ||
202 | test_expect_success 'prompt - merge' ' | |
4fe00b4f | 203 | printf " (b1|MERGING)" >expected && |
963c0407 SG |
204 | git checkout b1 && |
205 | test_when_finished "git checkout master" && | |
206 | test_must_fail git merge b2 && | |
207 | test_when_finished "git reset --hard" && | |
4fe00b4f | 208 | __git_ps1 >"$actual" && |
963c0407 SG |
209 | test_cmp expected "$actual" |
210 | ' | |
211 | ||
212 | test_expect_success 'prompt - cherry-pick' ' | |
4fe00b4f | 213 | printf " (master|CHERRY-PICKING)" >expected && |
e981bf75 PW |
214 | test_must_fail git cherry-pick b1 b1^ && |
215 | test_when_finished "git cherry-pick --abort" && | |
216 | __git_ps1 >"$actual" && | |
217 | test_cmp expected "$actual" && | |
218 | git reset --merge && | |
219 | test_must_fail git rev-parse CHERRY_PICK_HEAD && | |
220 | __git_ps1 >"$actual" && | |
221 | test_cmp expected "$actual" | |
222 | ' | |
223 | ||
224 | test_expect_success 'prompt - revert' ' | |
225 | printf " (master|REVERTING)" >expected && | |
226 | test_must_fail git revert b1^ b1 && | |
227 | test_when_finished "git revert --abort" && | |
228 | __git_ps1 >"$actual" && | |
229 | test_cmp expected "$actual" && | |
230 | git reset --merge && | |
231 | test_must_fail git rev-parse REVERT_HEAD && | |
4fe00b4f | 232 | __git_ps1 >"$actual" && |
963c0407 SG |
233 | test_cmp expected "$actual" |
234 | ' | |
235 | ||
236 | test_expect_success 'prompt - bisect' ' | |
4fe00b4f | 237 | printf " (master|BISECTING)" >expected && |
963c0407 SG |
238 | git bisect start && |
239 | test_when_finished "git bisect reset" && | |
4fe00b4f | 240 | __git_ps1 >"$actual" && |
963c0407 SG |
241 | test_cmp expected "$actual" |
242 | ' | |
243 | ||
244 | test_expect_success 'prompt - dirty status indicator - clean' ' | |
4fe00b4f | 245 | printf " (master)" >expected && |
963c0407 SG |
246 | ( |
247 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 248 | __git_ps1 >"$actual" |
963c0407 SG |
249 | ) && |
250 | test_cmp expected "$actual" | |
251 | ' | |
252 | ||
253 | test_expect_success 'prompt - dirty status indicator - dirty worktree' ' | |
4fe00b4f SG |
254 | printf " (master *)" >expected && |
255 | echo "dirty" >file && | |
963c0407 SG |
256 | test_when_finished "git reset --hard" && |
257 | ( | |
258 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 259 | __git_ps1 >"$actual" |
963c0407 SG |
260 | ) && |
261 | test_cmp expected "$actual" | |
262 | ' | |
263 | ||
264 | test_expect_success 'prompt - dirty status indicator - dirty index' ' | |
4fe00b4f SG |
265 | printf " (master +)" >expected && |
266 | echo "dirty" >file && | |
963c0407 SG |
267 | test_when_finished "git reset --hard" && |
268 | git add -u && | |
269 | ( | |
270 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 271 | __git_ps1 >"$actual" |
963c0407 SG |
272 | ) && |
273 | test_cmp expected "$actual" | |
274 | ' | |
275 | ||
276 | test_expect_success 'prompt - dirty status indicator - dirty index and worktree' ' | |
4fe00b4f SG |
277 | printf " (master *+)" >expected && |
278 | echo "dirty index" >file && | |
963c0407 SG |
279 | test_when_finished "git reset --hard" && |
280 | git add -u && | |
4fe00b4f | 281 | echo "dirty worktree" >file && |
963c0407 SG |
282 | ( |
283 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 284 | __git_ps1 >"$actual" |
963c0407 SG |
285 | ) && |
286 | test_cmp expected "$actual" | |
287 | ' | |
288 | ||
a30d11eb SG |
289 | test_expect_success 'prompt - dirty status indicator - orphan branch - clean' ' |
290 | printf " (orphan #)" >expected && | |
291 | test_when_finished "git checkout master" && | |
292 | git checkout --orphan orphan && | |
293 | git reset --hard && | |
294 | ( | |
295 | GIT_PS1_SHOWDIRTYSTATE=y && | |
296 | __git_ps1 >"$actual" | |
297 | ) && | |
298 | test_cmp expected "$actual" | |
299 | ' | |
300 | ||
c26f70ce | 301 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index' ' |
a30d11eb SG |
302 | printf " (orphan +)" >expected && |
303 | test_when_finished "git checkout master" && | |
304 | git checkout --orphan orphan && | |
305 | ( | |
306 | GIT_PS1_SHOWDIRTYSTATE=y && | |
307 | __git_ps1 >"$actual" | |
308 | ) && | |
309 | test_cmp expected "$actual" | |
310 | ' | |
311 | ||
c26f70ce | 312 | test_expect_success 'prompt - dirty status indicator - orphan branch - dirty index and worktree' ' |
a30d11eb SG |
313 | printf " (orphan *+)" >expected && |
314 | test_when_finished "git checkout master" && | |
315 | git checkout --orphan orphan && | |
316 | >file && | |
963c0407 SG |
317 | ( |
318 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 319 | __git_ps1 >"$actual" |
963c0407 SG |
320 | ) && |
321 | test_cmp expected "$actual" | |
322 | ' | |
323 | ||
dc7e7bce | 324 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config disabled' ' |
4fe00b4f SG |
325 | printf " (master)" >expected && |
326 | echo "dirty" >file && | |
963c0407 SG |
327 | test_when_finished "git reset --hard" && |
328 | test_config bash.showDirtyState false && | |
dc7e7bce MEW |
329 | ( |
330 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 331 | __git_ps1 >"$actual" |
dc7e7bce MEW |
332 | ) && |
333 | test_cmp expected "$actual" | |
334 | ' | |
335 | ||
336 | test_expect_success 'prompt - dirty status indicator - shell variable unset with config enabled' ' | |
4fe00b4f SG |
337 | printf " (master)" >expected && |
338 | echo "dirty" >file && | |
dc7e7bce MEW |
339 | test_when_finished "git reset --hard" && |
340 | test_config bash.showDirtyState true && | |
341 | ( | |
342 | sane_unset GIT_PS1_SHOWDIRTYSTATE && | |
4fe00b4f | 343 | __git_ps1 >"$actual" |
dc7e7bce MEW |
344 | ) && |
345 | test_cmp expected "$actual" | |
346 | ' | |
347 | ||
348 | test_expect_success 'prompt - dirty status indicator - shell variable set with config disabled' ' | |
4fe00b4f SG |
349 | printf " (master)" >expected && |
350 | echo "dirty" >file && | |
dc7e7bce MEW |
351 | test_when_finished "git reset --hard" && |
352 | test_config bash.showDirtyState false && | |
353 | ( | |
354 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 355 | __git_ps1 >"$actual" |
dc7e7bce MEW |
356 | ) && |
357 | test_cmp expected "$actual" | |
358 | ' | |
359 | ||
360 | test_expect_success 'prompt - dirty status indicator - shell variable set with config enabled' ' | |
4fe00b4f SG |
361 | printf " (master *)" >expected && |
362 | echo "dirty" >file && | |
dc7e7bce MEW |
363 | test_when_finished "git reset --hard" && |
364 | test_config bash.showDirtyState true && | |
963c0407 SG |
365 | ( |
366 | GIT_PS1_SHOWDIRTYSTATE=y && | |
4fe00b4f | 367 | __git_ps1 >"$actual" |
963c0407 SG |
368 | ) && |
369 | test_cmp expected "$actual" | |
370 | ' | |
371 | ||
372 | test_expect_success 'prompt - dirty status indicator - not shown inside .git directory' ' | |
4fe00b4f SG |
373 | printf " (GIT_DIR!)" >expected && |
374 | echo "dirty" >file && | |
963c0407 SG |
375 | test_when_finished "git reset --hard" && |
376 | ( | |
377 | GIT_PS1_SHOWDIRTYSTATE=y && | |
378 | cd .git && | |
4fe00b4f | 379 | __git_ps1 >"$actual" |
963c0407 SG |
380 | ) && |
381 | test_cmp expected "$actual" | |
382 | ' | |
383 | ||
384 | test_expect_success 'prompt - stash status indicator - no stash' ' | |
4fe00b4f | 385 | printf " (master)" >expected && |
963c0407 SG |
386 | ( |
387 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 388 | __git_ps1 >"$actual" |
963c0407 SG |
389 | ) && |
390 | test_cmp expected "$actual" | |
391 | ' | |
392 | ||
393 | test_expect_success 'prompt - stash status indicator - stash' ' | |
4fe00b4f | 394 | printf " (master $)" >expected && |
963c0407 SG |
395 | echo 2 >file && |
396 | git stash && | |
397 | test_when_finished "git stash drop" && | |
dd0b72cb | 398 | git pack-refs --all && |
963c0407 SG |
399 | ( |
400 | GIT_PS1_SHOWSTASHSTATE=y && | |
4fe00b4f | 401 | __git_ps1 >"$actual" |
963c0407 SG |
402 | ) && |
403 | test_cmp expected "$actual" | |
404 | ' | |
405 | ||
406 | test_expect_success 'prompt - stash status indicator - not shown inside .git directory' ' | |
4fe00b4f | 407 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
408 | echo 2 >file && |
409 | git stash && | |
410 | test_when_finished "git stash drop" && | |
411 | ( | |
412 | GIT_PS1_SHOWSTASHSTATE=y && | |
413 | cd .git && | |
4fe00b4f | 414 | __git_ps1 >"$actual" |
963c0407 SG |
415 | ) && |
416 | test_cmp expected "$actual" | |
417 | ' | |
418 | ||
419 | test_expect_success 'prompt - untracked files status indicator - no untracked files' ' | |
4fe00b4f | 420 | printf " (master)" >expected && |
963c0407 SG |
421 | ( |
422 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
423 | cd otherrepo && | |
4fe00b4f | 424 | __git_ps1 >"$actual" |
963c0407 SG |
425 | ) && |
426 | test_cmp expected "$actual" | |
427 | ' | |
428 | ||
429 | test_expect_success 'prompt - untracked files status indicator - untracked files' ' | |
4fe00b4f | 430 | printf " (master %%)" >expected && |
963c0407 SG |
431 | ( |
432 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 433 | __git_ps1 >"$actual" |
6bfab998 SG |
434 | ) && |
435 | test_cmp expected "$actual" | |
436 | ' | |
437 | ||
438 | test_expect_success 'prompt - untracked files status indicator - empty untracked dir' ' | |
439 | printf " (master)" >expected && | |
440 | mkdir otherrepo/untracked-dir && | |
441 | test_when_finished "rm -rf otherrepo/untracked-dir" && | |
442 | ( | |
443 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
444 | cd otherrepo && | |
445 | __git_ps1 >"$actual" | |
446 | ) && | |
447 | test_cmp expected "$actual" | |
448 | ' | |
449 | ||
450 | test_expect_success 'prompt - untracked files status indicator - non-empty untracked dir' ' | |
451 | printf " (master %%)" >expected && | |
452 | mkdir otherrepo/untracked-dir && | |
453 | test_when_finished "rm -rf otherrepo/untracked-dir" && | |
454 | >otherrepo/untracked-dir/untracked-file && | |
455 | ( | |
456 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
457 | cd otherrepo && | |
458 | __git_ps1 >"$actual" | |
963c0407 SG |
459 | ) && |
460 | test_cmp expected "$actual" | |
461 | ' | |
462 | ||
9bdc5173 CT |
463 | test_expect_success 'prompt - untracked files status indicator - untracked files outside cwd' ' |
464 | printf " (master %%)" >expected && | |
465 | ( | |
466 | mkdir -p ignored_dir && | |
467 | cd ignored_dir && | |
468 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
469 | __git_ps1 >"$actual" | |
470 | ) && | |
471 | test_cmp expected "$actual" | |
472 | ' | |
473 | ||
58978e82 | 474 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config disabled' ' |
4fe00b4f | 475 | printf " (master)" >expected && |
58978e82 MEW |
476 | test_config bash.showUntrackedFiles false && |
477 | ( | |
478 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 479 | __git_ps1 >"$actual" |
58978e82 MEW |
480 | ) && |
481 | test_cmp expected "$actual" | |
482 | ' | |
483 | ||
484 | test_expect_success 'prompt - untracked files status indicator - shell variable unset with config enabled' ' | |
4fe00b4f | 485 | printf " (master)" >expected && |
58978e82 MEW |
486 | test_config bash.showUntrackedFiles true && |
487 | ( | |
488 | sane_unset GIT_PS1_SHOWUNTRACKEDFILES && | |
4fe00b4f | 489 | __git_ps1 >"$actual" |
58978e82 MEW |
490 | ) && |
491 | test_cmp expected "$actual" | |
492 | ' | |
493 | ||
494 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config disabled' ' | |
4fe00b4f | 495 | printf " (master)" >expected && |
58978e82 MEW |
496 | test_config bash.showUntrackedFiles false && |
497 | ( | |
498 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 499 | __git_ps1 >"$actual" |
58978e82 MEW |
500 | ) && |
501 | test_cmp expected "$actual" | |
502 | ' | |
503 | ||
504 | test_expect_success 'prompt - untracked files status indicator - shell variable set with config enabled' ' | |
4fe00b4f | 505 | printf " (master %%)" >expected && |
58978e82 MEW |
506 | test_config bash.showUntrackedFiles true && |
507 | ( | |
508 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
4fe00b4f | 509 | __git_ps1 >"$actual" |
58978e82 MEW |
510 | ) && |
511 | test_cmp expected "$actual" | |
512 | ' | |
513 | ||
963c0407 | 514 | test_expect_success 'prompt - untracked files status indicator - not shown inside .git directory' ' |
4fe00b4f | 515 | printf " (GIT_DIR!)" >expected && |
963c0407 SG |
516 | ( |
517 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
518 | cd .git && | |
4fe00b4f | 519 | __git_ps1 >"$actual" |
963c0407 SG |
520 | ) && |
521 | test_cmp expected "$actual" | |
522 | ' | |
523 | ||
524 | test_expect_success 'prompt - format string starting with dash' ' | |
4fe00b4f SG |
525 | printf -- "-master" >expected && |
526 | __git_ps1 "-%s" >"$actual" && | |
963c0407 SG |
527 | test_cmp expected "$actual" |
528 | ' | |
529 | ||
1572e18e | 530 | test_expect_success 'prompt - pc mode' ' |
8976500c | 531 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmaster" >expected && |
1572e18e EA |
532 | ( |
533 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && | |
1c5e94f4 | 534 | test_must_be_empty "$actual" && |
8976500c | 535 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
536 | ) && |
537 | test_cmp expected "$actual" | |
538 | ' | |
539 | ||
540 | test_expect_success 'prompt - bash color pc mode - branch name' ' | |
8976500c | 541 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
542 | ( |
543 | GIT_PS1_SHOWCOLORHINTS=y && | |
cff4243d | 544 | __git_ps1 "BEFORE:" ":AFTER" >"$actual" && |
8976500c | 545 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
546 | ) && |
547 | test_cmp expected "$actual" | |
548 | ' | |
549 | ||
550 | test_expect_success 'prompt - bash color pc mode - detached head' ' | |
8976500c | 551 | printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected && |
1572e18e EA |
552 | git checkout b1^ && |
553 | test_when_finished "git checkout master" && | |
554 | ( | |
555 | GIT_PS1_SHOWCOLORHINTS=y && | |
556 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 557 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
558 | ) && |
559 | test_cmp expected "$actual" | |
560 | ' | |
561 | ||
562 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' ' | |
8976500c | 563 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
564 | echo "dirty" >file && |
565 | test_when_finished "git reset --hard" && | |
566 | ( | |
567 | GIT_PS1_SHOWDIRTYSTATE=y && | |
568 | GIT_PS1_SHOWCOLORHINTS=y && | |
569 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 570 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
571 | ) && |
572 | test_cmp expected "$actual" | |
573 | ' | |
574 | ||
575 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' ' | |
8976500c | 576 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
577 | echo "dirty" >file && |
578 | test_when_finished "git reset --hard" && | |
579 | git add -u && | |
580 | ( | |
581 | GIT_PS1_SHOWDIRTYSTATE=y && | |
582 | GIT_PS1_SHOWCOLORHINTS=y && | |
583 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 584 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
585 | ) && |
586 | test_cmp expected "$actual" | |
587 | ' | |
588 | ||
589 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' | |
8976500c | 590 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
591 | echo "dirty index" >file && |
592 | test_when_finished "git reset --hard" && | |
593 | git add -u && | |
594 | echo "dirty worktree" >file && | |
595 | ( | |
596 | GIT_PS1_SHOWCOLORHINTS=y && | |
597 | GIT_PS1_SHOWDIRTYSTATE=y && | |
598 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 599 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
600 | ) && |
601 | test_cmp expected "$actual" | |
602 | ' | |
603 | ||
604 | test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' ' | |
8976500c | 605 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
606 | ( |
607 | GIT_PS1_SHOWDIRTYSTATE=y && | |
608 | GIT_PS1_SHOWCOLORHINTS=y && | |
609 | cd otherrepo && | |
610 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 611 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
612 | ) && |
613 | test_cmp expected "$actual" | |
614 | ' | |
615 | ||
616 | test_expect_success 'prompt - bash color pc mode - inside .git directory' ' | |
8976500c | 617 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected && |
1572e18e EA |
618 | echo "dirty" >file && |
619 | test_when_finished "git reset --hard" && | |
620 | ( | |
621 | GIT_PS1_SHOWDIRTYSTATE=y && | |
622 | GIT_PS1_SHOWCOLORHINTS=y && | |
623 | cd .git && | |
624 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 625 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
626 | ) && |
627 | test_cmp expected "$actual" | |
628 | ' | |
629 | ||
630 | test_expect_success 'prompt - bash color pc mode - stash status indicator' ' | |
8976500c | 631 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
632 | echo 2 >file && |
633 | git stash && | |
634 | test_when_finished "git stash drop" && | |
635 | ( | |
636 | GIT_PS1_SHOWSTASHSTATE=y && | |
637 | GIT_PS1_SHOWCOLORHINTS=y && | |
638 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 639 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
640 | ) && |
641 | test_cmp expected "$actual" | |
642 | ' | |
643 | ||
644 | test_expect_success 'prompt - bash color pc mode - untracked files status indicator' ' | |
8976500c | 645 | printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmaster" >expected && |
1572e18e EA |
646 | ( |
647 | GIT_PS1_SHOWUNTRACKEDFILES=y && | |
648 | GIT_PS1_SHOWCOLORHINTS=y && | |
649 | __git_ps1 "BEFORE:" ":AFTER" && | |
8976500c | 650 | printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" |
1572e18e EA |
651 | ) && |
652 | test_cmp expected "$actual" | |
653 | ' | |
654 | ||
f3bd62d0 | 655 | test_expect_success 'prompt - zsh color pc mode' ' |
1e4119c8 | 656 | printf "BEFORE: (%%F{green}master%%f):AFTER" >expected && |
1572e18e EA |
657 | ( |
658 | ZSH_VERSION=5.0.0 && | |
659 | GIT_PS1_SHOWCOLORHINTS=y && | |
1e4119c8 RH |
660 | __git_ps1 "BEFORE:" ":AFTER" && |
661 | printf "%s" "$PS1" >"$actual" | |
1572e18e EA |
662 | ) && |
663 | test_cmp expected "$actual" | |
664 | ' | |
665 | ||
0120b8c8 JA |
666 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled' ' |
667 | printf " (master)" >expected && | |
668 | test_config bash.hideIfPwdIgnored false && | |
669 | ( | |
670 | cd ignored_dir && | |
671 | __git_ps1 >"$actual" | |
672 | ) && | |
673 | test_cmp expected "$actual" | |
674 | ' | |
675 | ||
676 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config disabled, pc mode' ' | |
677 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
678 | test_config bash.hideIfPwdIgnored false && | |
679 | ( | |
680 | cd ignored_dir && | |
681 | __git_ps1 "BEFORE:" ":AFTER" && | |
682 | printf "%s" "$PS1" >"$actual" | |
683 | ) && | |
684 | test_cmp expected "$actual" | |
685 | ' | |
686 | ||
687 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset' ' | |
688 | printf " (master)" >expected && | |
689 | ( | |
690 | cd ignored_dir && | |
691 | __git_ps1 >"$actual" | |
692 | ) && | |
693 | test_cmp expected "$actual" | |
694 | ' | |
695 | ||
696 | test_expect_success 'prompt - hide if pwd ignored - env var unset, config unset, pc mode' ' | |
697 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
698 | ( | |
699 | cd ignored_dir && | |
700 | __git_ps1 "BEFORE:" ":AFTER" && | |
701 | printf "%s" "$PS1" >"$actual" | |
702 | ) && | |
703 | test_cmp expected "$actual" | |
704 | ' | |
705 | ||
706 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled' ' | |
707 | printf " (master)" >expected && | |
708 | test_config bash.hideIfPwdIgnored false && | |
709 | ( | |
710 | cd ignored_dir && | |
711 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
712 | __git_ps1 >"$actual" | |
713 | ) && | |
714 | test_cmp expected "$actual" | |
715 | ' | |
716 | ||
717 | test_expect_success 'prompt - hide if pwd ignored - env var set, config disabled, pc mode' ' | |
718 | printf "BEFORE: (\${__git_ps1_branch_name}):AFTER" >expected && | |
719 | test_config bash.hideIfPwdIgnored false && | |
720 | ( | |
721 | cd ignored_dir && | |
722 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
723 | __git_ps1 "BEFORE:" ":AFTER" && | |
724 | printf "%s" "$PS1" >"$actual" | |
725 | ) && | |
726 | test_cmp expected "$actual" | |
727 | ' | |
728 | ||
729 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset' ' | |
0120b8c8 JA |
730 | ( |
731 | cd ignored_dir && | |
732 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
733 | __git_ps1 >"$actual" | |
734 | ) && | |
1c5e94f4 | 735 | test_must_be_empty "$actual" |
0120b8c8 JA |
736 | ' |
737 | ||
738 | test_expect_success 'prompt - hide if pwd ignored - env var set, config unset, pc mode' ' | |
739 | printf "BEFORE::AFTER" >expected && | |
740 | ( | |
741 | cd ignored_dir && | |
742 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
743 | __git_ps1 "BEFORE:" ":AFTER" && | |
744 | printf "%s" "$PS1" >"$actual" | |
745 | ) && | |
746 | test_cmp expected "$actual" | |
747 | ' | |
748 | ||
d31f298f | 749 | test_expect_success 'prompt - hide if pwd ignored - inside gitdir' ' |
0120b8c8 JA |
750 | printf " (GIT_DIR!)" >expected && |
751 | ( | |
752 | GIT_PS1_HIDE_IF_PWD_IGNORED=y && | |
753 | cd .git && | |
d31f298f | 754 | __git_ps1 >"$actual" |
0120b8c8 JA |
755 | ) && |
756 | test_cmp expected "$actual" | |
757 | ' | |
758 | ||
963c0407 | 759 | test_done |