Skip to content

Commit ef85155

Browse files
authored
Don't try to find upstream in detached HEAD (#2387)
HEAD is detached for new branches.
1 parent 786f8ea commit ef85155

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

scripts/clang-format-diff.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ set -o pipefail
55

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

1627
MERGE_BASE=$(git merge-base $BRANCH HEAD)

0 commit comments

Comments
 (0)