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