File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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.
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
You can’t perform that action at this time.
0 commit comments