Skip to content

Commit 94c9167

Browse files
committed
Merge branch 'jp/prompt-clear-before-upstream-mark' into seen
Bash command line prompt (in contrib/) update. * jp/prompt-clear-before-upstream-mark: git-prompt: fix expansion of branch colour codes
2 parents 1d233cd + 0e5d9ef commit 94c9167

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

contrib/completion/git-prompt.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,21 +556,21 @@ __git_ps1 ()
556556
fi
557557
fi
558558

559-
b=${b##refs/heads/}
560559
local z="${GIT_PS1_STATESEPARATOR-" "}"
561560

561+
b=${b##refs/heads/}
562+
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
563+
__git_ps1_branch_name=$b
564+
b="\${__git_ps1_branch_name}"
565+
fi
566+
562567
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
563568
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
564569
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
565570
__git_ps1_colorize_gitstring
566571
fi
567572
fi
568573

569-
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
570-
__git_ps1_branch_name=$b
571-
b="\${__git_ps1_branch_name}"
572-
fi
573-
574574
local f="$h$w$i$s$u$p"
575575
local gitstring="$c$b${f:+$z$f}${sparse}$r${upstream}"
576576

t/t9903-bash-prompt.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ test_expect_success 'prompt - pc mode' '
541541
'
542542

543543
test_expect_success 'prompt - bash color pc mode - branch name' '
544-
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\n${c_green}main${c_clear}" >expected &&
544+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmain" >expected &&
545545
(
546546
GIT_PS1_SHOWCOLORHINTS=y &&
547547
__git_ps1 "BEFORE:" ":AFTER" >"$actual" &&
@@ -551,7 +551,7 @@ test_expect_success 'prompt - bash color pc mode - branch name' '
551551
'
552552

553553
test_expect_success 'prompt - bash color pc mode - detached head' '
554-
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\n${c_red}(%s...)"${c_clear} $(git log -1 --format="%h" b1^) >expected &&
554+
printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected &&
555555
git checkout b1^ &&
556556
test_when_finished "git checkout main" &&
557557
(
@@ -563,7 +563,7 @@ test_expect_success 'prompt - bash color pc mode - detached head' '
563563
'
564564

565565
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' '
566-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_red}*${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
566+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmain" >expected &&
567567
echo "dirty" >file &&
568568
test_when_finished "git reset --hard" &&
569569
(
@@ -576,7 +576,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt
576576
'
577577

578578
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' '
579-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_green}+${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
579+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmain" >expected &&
580580
echo "dirty" >file &&
581581
test_when_finished "git reset --hard" &&
582582
git add -u &&
@@ -590,7 +590,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt
590590
'
591591

592592
test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' '
593-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_red}*${c_clear}${c_green}+${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
593+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}${c_green}+${c_clear}):AFTER\\nmain" >expected &&
594594
echo "dirty index" >file &&
595595
test_when_finished "git reset --hard" &&
596596
git add -u &&
@@ -605,7 +605,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt
605605
'
606606

607607
test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' '
608-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_green}#${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
608+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmain" >expected &&
609609
(
610610
GIT_PS1_SHOWDIRTYSTATE=y &&
611611
GIT_PS1_SHOWCOLORHINTS=y &&
@@ -617,7 +617,7 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - befo
617617
'
618618

619619
test_expect_success 'prompt - bash color pc mode - inside .git directory' '
620-
printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\n${c_green}GIT_DIR!${c_clear}" >expected &&
620+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected &&
621621
echo "dirty" >file &&
622622
test_when_finished "git reset --hard" &&
623623
(
@@ -631,7 +631,7 @@ test_expect_success 'prompt - bash color pc mode - inside .git directory' '
631631
'
632632

633633
test_expect_success 'prompt - bash color pc mode - stash status indicator' '
634-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_lblue}\$${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
634+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmain" >expected &&
635635
echo 2 >file &&
636636
git stash &&
637637
test_when_finished "git stash drop" &&
@@ -645,7 +645,7 @@ test_expect_success 'prompt - bash color pc mode - stash status indicator' '
645645
'
646646

647647
test_expect_success 'prompt - bash color pc mode - untracked files status indicator' '
648-
printf "BEFORE: (\${__git_ps1_branch_name} ${c_red}%%${c_clear}):AFTER\\n${c_green}main${c_clear}" >expected &&
648+
printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmain" >expected &&
649649
(
650650
GIT_PS1_SHOWUNTRACKEDFILES=y &&
651651
GIT_PS1_SHOWCOLORHINTS=y &&

0 commit comments

Comments
 (0)