Skip to content

Commit

Permalink
More carefully get the merge base's parent.
Browse files Browse the repository at this point in the history
  - If the merge base is a root (i.e., it has no parents), then
    `$MERGE_BASE^` is not a valid reference.

  - Be more careful.
  • Loading branch information
nwalfield committed Aug 31, 2023
1 parent 2aaf328 commit 2673d96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/fast-forward.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,20 @@ LOG=$(mktemp)
echo " Branches appear to have diverged at $MERGE_BASE:"
echo
echo '```shell'

# We don't want to displays the commits before the merge
# base. We need to be careful though: if the merge base
# is a root (i.e., it has no parents), then $MERGE_BASE^
# is not a valid reference.
if test x$(git cat-file -t "$MERGE_BASE^") = xcommit
then
EXCLUDE="^$MERGE_BASE^"
else
EXCLUDE=
fi

git log --pretty=oneline --graph \
"^$MERGE_BASE^" "$BASE_SHA" "$PR_SHA"
$EXCLUDE "$BASE_SHA" "$PR_SHA"
echo
git log --decorate=short -n 1 "$MERGE_BASE"
echo '```'
Expand Down

0 comments on commit 2673d96

Please sign in to comment.