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