Skip to content

Commit

Permalink
Merge branch 'pw/prompt-cherry-pick-revert-fix' into next
Browse files Browse the repository at this point in the history
When one step in multi step cherry-pick or revert is reset or
committed, the command line prompt script failed to notice the
current status, which has been improved.

* pw/prompt-cherry-pick-revert-fix:
  git-prompt: improve cherry-pick/revert detection
  • Loading branch information
gitster committed Jul 10, 2019
2 parents 351952f + e981bf7 commit bf8f0af
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
37 changes: 33 additions & 4 deletions contrib/completion/git-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,37 @@ __git_eread ()
test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
}

# see if a cherry-pick or revert is in progress, if the user has committed a
# conflict resolution with 'git commit' in the middle of a sequence of picks or
# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
# the todo file.
__git_sequencer_status ()
{
local todo
if test -f "$g/CHERRY_PICK_HEAD"
then
r="|CHERRY-PICKING"
return 0;
elif test -f "$g/REVERT_HEAD"
then
r="|REVERTING"
return 0;
elif __git_eread "$g/sequencer/todo" todo
then
case "$todo" in
p[\ \ ]|pick[\ \ ]*)
r="|CHERRY-PICKING"
return 0
;;
revert[\ \ ]*)
r="|REVERTING"
return 0
;;
esac
fi
return 1
}

# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution
# in this mode it prints text to add to bash PS1 prompt (includes branch name)
Expand Down Expand Up @@ -417,10 +448,8 @@ __git_ps1 ()
fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif __git_sequencer_status; then
:
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
Expand Down
20 changes: 18 additions & 2 deletions t/t9903-bash-prompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,24 @@ test_expect_success 'prompt - merge' '

test_expect_success 'prompt - cherry-pick' '
printf " (master|CHERRY-PICKING)" >expected &&
test_must_fail git cherry-pick b1 &&
test_when_finished "git reset --hard" &&
test_must_fail git cherry-pick b1 b1^ &&
test_when_finished "git cherry-pick --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual" &&
git reset --merge &&
test_must_fail git rev-parse CHERRY_PICK_HEAD &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'

test_expect_success 'prompt - revert' '
printf " (master|REVERTING)" >expected &&
test_must_fail git revert b1^ b1 &&
test_when_finished "git revert --abort" &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual" &&
git reset --merge &&
test_must_fail git rev-parse REVERT_HEAD &&
__git_ps1 >"$actual" &&
test_cmp expected "$actual"
'
Expand Down

0 comments on commit bf8f0af

Please sign in to comment.