Skip to content

Commit 33585ea

Browse files
committed
Create branch if needed option
1 parent 0a14457 commit 33585ea

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,13 @@ inputs:
4848
description: '[Optional] The directory to wipe and replace in the target repository'
4949
default: ''
5050
required: false
51-
51+
create-target-branch-if-needed:
52+
type: boolean
53+
description: >-
54+
[Optional] create target branch if not exist. Defaults to `false`
55+
default: false
56+
required: false
57+
5258
runs:
5359
using: docker
5460
image: Dockerfile
@@ -64,6 +70,7 @@ runs:
6470
- '${{ inputs.target-branch }}'
6571
- '${{ inputs.commit-message }}'
6672
- '${{ inputs.target-directory }}'
73+
- '${{ inputs.create-target-branch-if-needed }}'
6774
branding:
6875
icon: git-commit
6976
color: green

entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DESTINATION_REPOSITORY_USERNAME="${8}"
1515
TARGET_BRANCH="${9}"
1616
COMMIT_MESSAGE="${10}"
1717
TARGET_DIRECTORY="${11}"
18+
CREATE_TARGET_BRANCH_IF_NEEDED="${12}"
1819

1920
if [ -z "$DESTINATION_REPOSITORY_USERNAME" ]
2021
then
@@ -70,6 +71,12 @@ git config --global user.name "$USER_NAME"
7071

7172
{
7273
git clone --single-branch --depth 1 --branch "$TARGET_BRANCH" "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
74+
} || {
75+
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = 'true' ] ; then
76+
git clone --single-branch --depth 1 "$GIT_CMD_REPOSITORY" "$CLONE_DIR"
77+
else
78+
false
79+
fi
7380
} || {
7481
echo "::error::Could not clone the destination repository. Command:"
7582
echo "::error::git clone --single-branch --branch $TARGET_BRANCH $GIT_CMD_REPOSITORY $CLONE_DIR"
@@ -137,6 +144,11 @@ echo "[+] Set directory is safe ($CLONE_DIR)"
137144
# TODO: review before releasing it as a version
138145
git config --global --add safe.directory "$CLONE_DIR"
139146

147+
148+
if [ "$CREATE_TARGET_BRANCH_IF_NEEDED" = 'true' ] ; then
149+
git checkout -b "$TARGET_BRANCH"
150+
fi
151+
140152
echo "[+] Adding git commit"
141153
git add .
142154

0 commit comments

Comments
 (0)