Skip to content

Commit 6158b1d

Browse files
committed
allow branch names with parenthesis
1 parent 72fd5e0 commit 6158b1d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

action.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ runs:
5050
resolve_default_branch() {
5151
git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@' || true
5252
}
53+
is_detached_marker() {
54+
local b="$1"
55+
[[ "$b" == "HEAD" || "$b" == "(no branch)" || "$b" == "(HEAD detached at "* || "$b" == "(HEAD detached from "* ]]
56+
}
57+
is_valid_branch_name() {
58+
local b="$1"
59+
git check-ref-format --branch "$b" >/dev/null 2>&1
60+
}
5361
5462
# --- Ensure we have enough history + refs ---
5563
# Ensure 'origin' exists but never rewrite an existing remote URL/config.
@@ -70,7 +78,7 @@ runs:
7078
BRANCH="${INPUT_BRANCH:-}"
7179
BRANCH="$(echo "$BRANCH" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')"
7280
if [[ -n "$BRANCH" ]]; then
73-
if [[ "$BRANCH" == "HEAD" || "$BRANCH" =~ ^\(.+\)$ ]]; then
81+
if is_detached_marker "$BRANCH" || ! is_valid_branch_name "$BRANCH"; then
7482
echo "Invalid explicit branch input: '$BRANCH'" >&2
7583
exit 1
7684
fi
@@ -158,10 +166,10 @@ runs:
158166
fi
159167
160168
# --- Last resorts: never return a detached HEAD string ---
161-
if [[ -z "$BRANCH" || "$BRANCH" == "HEAD" || "$BRANCH" =~ ^\(.+\)$ ]]; then
169+
if [[ -z "$BRANCH" ]] || is_detached_marker "$BRANCH" || ! is_valid_branch_name "$BRANCH"; then
162170
BRANCH="$(resolve_default_branch)"
163171
fi
164-
if [[ -z "$BRANCH" || "$BRANCH" == "HEAD" || "$BRANCH" =~ ^\(.+\)$ ]]; then
172+
if [[ -z "$BRANCH" ]] || is_detached_marker "$BRANCH" || ! is_valid_branch_name "$BRANCH"; then
165173
echo "Could not determine branch (still detached at a tag). Consider actions/checkout with 'fetch-depth: 0'." >&2
166174
exit 1
167175
fi

0 commit comments

Comments
 (0)