From 2673d968aeffa01668adbc09d658a091e240d12d Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Thu, 31 Aug 2023 12:50:19 +0200 Subject: [PATCH] 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. --- src/fast-forward.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fast-forward.sh b/src/fast-forward.sh index f249873..6e9631f 100755 --- a/src/fast-forward.sh +++ b/src/fast-forward.sh @@ -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 '```'