Skip to content

Commit a572a5d

Browse files
committed
Merge branch 'jd/prompt-show-conflict'
The bash prompt (in contrib/) learned to optionally indicate when the index is unmerged. * jd/prompt-show-conflict: git-prompt: show presence of unresolved conflicts at command prompt
2 parents bc820cf + e03acd0 commit a572a5d

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

contrib/completion/git-prompt.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
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

t/t9903-bash-prompt.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
762778
test_done

0 commit comments

Comments
 (0)