Skip to content

Commit 2673d96

Browse files
committed
More carefully get the merge base's parent.
- If the merge base is a root (i.e., it has no parents), then `$MERGE_BASE^` is not a valid reference. - Be more careful.
1 parent 2aaf328 commit 2673d96

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/fast-forward.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,20 @@ LOG=$(mktemp)
248248
echo " Branches appear to have diverged at $MERGE_BASE:"
249249
echo
250250
echo '```shell'
251+
252+
# We don't want to displays the commits before the merge
253+
# base. We need to be careful though: if the merge base
254+
# is a root (i.e., it has no parents), then $MERGE_BASE^
255+
# is not a valid reference.
256+
if test x$(git cat-file -t "$MERGE_BASE^") = xcommit
257+
then
258+
EXCLUDE="^$MERGE_BASE^"
259+
else
260+
EXCLUDE=
261+
fi
262+
251263
git log --pretty=oneline --graph \
252-
"^$MERGE_BASE^" "$BASE_SHA" "$PR_SHA"
264+
$EXCLUDE "$BASE_SHA" "$PR_SHA"
253265
echo
254266
git log --decorate=short -n 1 "$MERGE_BASE"
255267
echo '```'

0 commit comments

Comments
 (0)