From a53d74f700f2982646d538e66ce35cbfc8d4e826 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Sat, 26 Feb 2022 05:09:14 -0500 Subject: [PATCH] fix: handle errors for repositories without any previous commit history (#404) * fix: Handle errors for repositories without any previous commit history Fixes: #365 * Update diff-sha.sh --- diff-sha.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/diff-sha.sh b/diff-sha.sh index fe2bcd48..153b5414 100644 --- a/diff-sha.sh +++ b/diff-sha.sh @@ -52,7 +52,11 @@ if [[ -z $GITHUB_BASE_REF ]]; then CURRENT_BRANCH=$TARGET_BRANCH if [[ -z $INPUT_BASE_SHA ]]; then - PREVIOUS_SHA=$(git rev-list --no-merges -n 1 HEAD^1 2>&1) && exit_status=$? || exit_status=$? + if [[ $(git rev-list --count HEAD) -gt 1 ]]; then + PREVIOUS_SHA=$(git rev-list --no-merges -n 1 HEAD^1 2>&1) && exit_status=$? || exit_status=$? + else + PREVIOUS_SHA=$CURRENT_SHA + fi else PREVIOUS_SHA=$INPUT_BASE_SHA && exit_status=$? || exit_status=$? TARGET_BRANCH=$(git name-rev --name-only "$PREVIOUS_SHA" 2>&1) && exit_status=$? || exit_status=$?