Skip to content

Commit

Permalink
Don't try to find upstream in detached HEAD (#2387)
Browse files Browse the repository at this point in the history
HEAD is detached for new branches.
  • Loading branch information
SoniEx2 authored Feb 8, 2024
1 parent 786f8ea commit ef85155
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion scripts/clang-format-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ set -o pipefail

if [ -n "$1" ]; then
BRANCH="$1"
elif [ "$CI" != "true" ]; then
echo "Please specify a base branch in the command line"
exit 1
elif [ -n "$GITHUB_EVENT_BEFORE" ] && [ "push" = "$GITHUB_EVENT_NAME" ]; then
BRANCH="$GITHUB_EVENT_BEFORE"
elif [ -n "$GITHUB_BASE_REF" ]; then
BRANCH="origin/$GITHUB_BASE_REF"
else
elif git symbolic-ref -q HEAD; then # check if we're in a branch
BRANCH="@{upstream}"
else
# in a detached HEAD.
# default to origin/main, this is a "last resort" to make this script do the
# right thing, and is only really here so it works when pushing a new branch,
# with the caveat that it assumes the base branch to be called "main".
# (this has been the case with wabt for a while. may fail if the repo lacks a
# "main" branch for some reason.)
BRANCH="origin/main"
fi

MERGE_BASE=$(git merge-base $BRANCH HEAD)
Expand Down

0 comments on commit ef85155

Please sign in to comment.