File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 8484# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
8585# by setting GIT_PS1_OMITSPARSESTATE.
8686#
87+ # If you would like to see a notification on the prompt when there are
88+ # unresolved conflicts, set GIT_PS1_SHOWCONFLICTSTATE to "yes". The
89+ # prompt will include "|CONFLICT".
90+ #
8791# If you would like to see more information about the identity of
8892# commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
8993# to one of these values:
@@ -508,6 +512,12 @@ __git_ps1 ()
508512 r=" $r $step /$total "
509513 fi
510514
515+ local conflict=" " # state indicator for unresolved conflicts
516+ if [[ " ${GIT_PS1_SHOWCONFLICTSTATE} " == " yes" ]] &&
517+ [[ $( git ls-files --unmerged 2> /dev/null) ]]; then
518+ conflict=" |CONFLICT"
519+ fi
520+
511521 local w=" "
512522 local i=" "
513523 local s=" "
@@ -572,7 +582,7 @@ __git_ps1 ()
572582 fi
573583
574584 local f=" $h$w$i$s$u$p "
575- local gitstring=" $c$b ${f: +$z$f }${sparse} $r ${upstream} "
585+ local gitstring=" $c$b ${f: +$z$f }${sparse} $r ${upstream}${conflict} "
576586
577587 if [ $pcmode = yes ]; then
578588 if [ " ${__git_printf_supports_v-} " != yes ]; then
Original file line number Diff line number Diff line change @@ -759,4 +759,20 @@ test_expect_success 'prompt - hide if pwd ignored - inside gitdir' '
759759 test_cmp expected "$actual"
760760'
761761
762+ test_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+
762778test_done
You can’t perform that action at this time.
0 commit comments