Skip to content

Commit e63633a

Browse files
🐛 Fix branch resolving
1 parent 4436b06 commit e63633a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

entrypoint.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ git remote set-url origin "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${INPUT_ORGAN
3131
git config --global user.name "${GITHUB_ACTOR}"
3232
git config --global user.email "${GITHUB_ACTOR}@users.noreply.${INPUT_ORGANIZATION_DOMAIN}"
3333

34+
get_current_branch() {
35+
local branch
36+
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || true)
37+
if [[ "${branch}" == "HEAD" ]]; then
38+
branch=""
39+
fi
40+
printf '%s' "${branch}"
41+
}
42+
3443
# Get changed files
3544
git add -A
3645
FILES_CHANGED=$(git diff --staged --name-status)
@@ -43,13 +52,13 @@ fi
4352
SKIP_BRANCH_CREATION=false
4453
if [[ -z ${FILES_CHANGED} && "${INPUT_AMEND}" != "true" ]]; then
4554
SKIP_BRANCH_CREATION=true
46-
BRANCH="$(git symbolic-ref --short -q HEAD)"
55+
BRANCH="$(get_current_branch)"
4756
echo -e "\n[INFO] No changes to commit and amend disabled; skipping branch creation."
4857
fi
4958

5059
if [[ "${SKIP_BRANCH_CREATION}" != "true" ]]; then
5160
# Setting branch name
52-
BRANCH="${INPUT_TARGET_BRANCH:-$(git symbolic-ref --short -q HEAD)}"
61+
BRANCH="${INPUT_TARGET_BRANCH:-$(get_current_branch)}"
5362
# Add timestamp to branch name
5463
if [[ "${INPUT_ADD_TIMESTAMP}" == "true" ]]; then
5564
TIMESTAMP=$(date -u +"%Y-%m-%dT%H-%M-%SZ")

0 commit comments

Comments
 (0)