@@ -766,6 +766,80 @@ jobs:
766766 git push --force --delete origin "${TO_DELETE}"
767767 env :
768768 TO_DELETE : ${{ steps.setup-test-branch.outputs.branch-name }}
769+
770+ test-allow-empty : # verify allow-empty: true creates a commit even when there are no file changes
771+ runs-on : ubuntu-latest
772+ needs : [check-not-fork]
773+ permissions :
774+ contents : write
775+ steps :
776+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
777+ with :
778+ persist-credentials : true
779+ - name : Setup test branch
780+ id : setup-test-branch
781+ run : |
782+ BRANCH_NAME="test_allow-empty-$(date +%s)"
783+
784+ git config --global user.name 'github-actions[bot]'
785+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
786+
787+ git checkout -b $BRANCH_NAME
788+ git push --set-upstream origin $BRANCH_NAME
789+
790+ # output status here to manually verify there are no file changes
791+ git status --porcelain=v2 --branch --untracked-files=no
792+
793+ PARENT_SHA=$(git rev-parse HEAD)
794+ echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
795+ echo "parent-sha=$PARENT_SHA" >> $GITHUB_OUTPUT
796+ - uses : ./
797+ id : test-action
798+ with :
799+ token : ${{ github.token }}
800+ allow-empty : true
801+ commit-message : ${{ steps.setup-test-branch.outputs.branch-name }}
802+ - name : Validate empty commit was created
803+ run : |
804+ if [[ -z "${RESPONSE}" ]]; then
805+ echo "Error: commit-response is empty; expected a commit to be created."
806+ exit 1
807+ fi
808+
809+ changedFilesIfAvailable=$(echo "${RESPONSE}" | jq -r '.data.createCommitOnBranch.commit.changedFilesIfAvailable')
810+ if [[ "$changedFilesIfAvailable" -ne 0 ]]; then
811+ echo "Error: changedFilesIfAvailable expected 0 but got $changedFilesIfAvailable."
812+ exit 1
813+ fi
814+
815+ # Fetch the branch from the remote and confirm the commit is truly empty
816+ # (its tree SHA equals its parent's tree SHA) and that HEAD advanced.
817+ git fetch origin "${BRANCH}"
818+ NEW_HEAD=$(git rev-parse "origin/${BRANCH}")
819+ if [[ "$NEW_HEAD" == "${PARENT_SHA}" ]]; then
820+ echo "Error: branch HEAD did not advance; no commit was created."
821+ exit 1
822+ fi
823+
824+ NEW_TREE=$(git rev-parse "origin/${BRANCH}^{tree}")
825+ PARENT_TREE=$(git rev-parse "origin/${BRANCH}~^{tree}")
826+ if [[ "$NEW_TREE" != "$PARENT_TREE" ]]; then
827+ echo "Error: new commit tree ($NEW_TREE) differs from parent tree ($PARENT_TREE); commit is not empty."
828+ exit 1
829+ fi
830+
831+ echo "Validation passed: empty commit created on top of ${PARENT_SHA}."
832+ env :
833+ RESPONSE : ${{ steps.test-action.outputs.commit-response }}
834+ BRANCH : ${{ steps.setup-test-branch.outputs.branch-name }}
835+ PARENT_SHA : ${{ steps.setup-test-branch.outputs.parent-sha }}
836+ - name : Delete test branch
837+ if : ${{ always() }}
838+ run : |
839+ git push --force --delete origin "${TO_DELETE}"
840+ env :
841+ TO_DELETE : ${{ steps.setup-test-branch.outputs.branch-name }}
842+
769843 test-persist-credentials-false-branch-on-remote :
770844 runs-on : ubuntu-latest
771845 needs : [check-not-fork]
0 commit comments