Skip to content

Support not pushing if the branch is empty #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
20 changes: 13 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 status --short | wc -l | xargs echo -n)" = "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