From 47211c97b5808d3e50a27b6696936326cd83df2b Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Thu, 10 Aug 2023 11:10:11 +0100 Subject: [PATCH 1/4] "Allow Empty Branches" config options --- action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 30d8e28..e54e975 100644 --- a/action.yml +++ b/action.yml @@ -54,6 +54,12 @@ inputs: [Optional] create target branch if not exist. Defaults to `false` default: false required: false + allow-empty-branches: + type: boolean + description: >- + [Optional] allow empty branches to be pushed. Defaults to `true` + default: true + required: false runs: using: docker @@ -71,6 +77,7 @@ runs: - '${{ inputs.commit-message }}' - '${{ inputs.target-directory }}' - '${{ inputs.create-target-branch-if-needed }}' + - '${{ inputs.allow-empty-branches }}' branding: icon: git-commit color: green From 15a6ec1f72e73f4caf4931160957397e60d2be66 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Thu, 10 Aug 2023 11:21:51 +0100 Subject: [PATCH 2/4] Support ALLOW_EMPTY_BRANCHES --- entrypoint.sh | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f5eb0da..242a468 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,7 @@ TARGET_BRANCH="${9}" COMMIT_MESSAGE="${10}" TARGET_DIRECTORY="${11}" CREATE_TARGET_BRANCH_IF_NEEDED="${12}" +ALLOW_EMPTY_BRANCHES="${13}" if [ -z "$DESTINATION_REPOSITORY_USERNAME" ] then @@ -166,10 +167,15 @@ git add . echo "[+] git status:" git status -echo "[+] git diff-index:" -# git diff-index : to avoid doing the git commit failing if there are no changes to be commit -git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE" - -echo "[+] Pushing git commit" -# --set-upstream: sets de branch when pushing to a branch that does not exist -git push "$GIT_CMD_REPOSITORY" --set-upstream "$TARGET_BRANCH" +if [ "$ALLOW_EMPTY_BRANCHES" = "false" ] && [ "$(git diff --numstat | wc -l | xargs echo -n)" -eq 0 ] +then + echo "[~] No changes have been made" +else + echo "[+] git diff-index:" + # git diff-index : to avoid doing the git commit failing if there are no changes to be commit + git diff-index --quiet HEAD || git commit --message "$COMMIT_MESSAGE" + + echo "[+] Pushing git commit" + # --set-upstream: sets de branch when pushing to a branch that does not exist + git push "$GIT_CMD_REPOSITORY" --set-upstream "$TARGET_BRANCH" +fi From 4296be5205370baf32228c283ed8cd5670deabfe Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Thu, 10 Aug 2023 11:31:42 +0100 Subject: [PATCH 3/4] Change to use `git status` --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 242a468..7f6272e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -167,7 +167,7 @@ git add . echo "[+] git status:" git status -if [ "$ALLOW_EMPTY_BRANCHES" = "false" ] && [ "$(git diff --numstat | wc -l | xargs echo -n)" -eq 0 ] +if [ "$ALLOW_EMPTY_BRANCHES" = "false" ] && [ "$(git status)" = "nothing to commit, working tree clean" ] then echo "[~] No changes have been made" else From 8d707905ec57c46621904e5c05d26468be390c91 Mon Sep 17 00:00:00 2001 From: Alex Bowers Date: Thu, 10 Aug 2023 11:38:18 +0100 Subject: [PATCH 4/4] Bug Fix --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 7f6272e..87c1ccf 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -167,7 +167,7 @@ git add . echo "[+] git status:" git status -if [ "$ALLOW_EMPTY_BRANCHES" = "false" ] && [ "$(git status)" = "nothing to commit, working tree clean" ] +if [ "$ALLOW_EMPTY_BRANCHES" = "false" ] && [ "$(git status --short | wc -l | xargs echo -n)" = "0" ] then echo "[~] No changes have been made" else