Skip to content

Add hooks to run shell snippets around git operations#411

Merged
stefanzweifel merged 11 commits into
masterfrom
git-auto-commit-hooks
Jun 28, 2026
Merged

Add hooks to run shell snippets around git operations#411
stefanzweifel merged 11 commits into
masterfrom
git-auto-commit-hooks

Conversation

@stefanzweifel

Copy link
Copy Markdown
Owner

Adds eight optional hook inputs that run inline shell snippets around each git operation the action performs (add, commit, tag, push).

Closes the long-standing ask for a generic extension point — e.g.
git fetch --unshallow before a shallow-clone commit (#365) and gives users of this Action more power.

Hooks

Hook Runs
before_add_hook / after_add_hook around git add
before_commit_hook / after_commit_hook around git commit
before_tag_hook / after_tag_hook around git tag (only when a tag is being created)
before_push_hook / after_push_hook around git push (skipped when skip_push: true)

Each hook is an inline shell snippet evaluated in the same bash process as the action, so it sees the same INPUT_* env vars and runs in the repository's working directory. A non-zero exit aborts the action
(consistent with the existing set -eu); users can append || true to ignore a failure. Hooks only fire when their underlying step actually runs — e.g. before_add_hook is skipped on a clean tree.

Example

- uses: stefanzweifel/git-auto-commit-action@v7
  with:
    before_add_hook: git fetch --unshallow

Or multi-line via YAML's |:

- uses: stefanzweifel/git-auto-commit-action@v7
  with:
    before_commit_hook: |
      echo "About to commit at $(date)"
      ./scripts/prepare-commit.sh

See the new Hooks section in README.md for full docs.

Guards against set -u aborting with 'unbound variable' if _run_hook is
ever called with only one argument.
The previous `refute [assert_equal ...]` line was silently a no-op:
`refute` invoked `[` (the test builtin) with literal arguments and
always saw the non-zero exit, so the check never actually compared
shas. Replace with a direct assertion that no commit_hash output was
written, which is what 'aborted before committing' really means here.
`before_add` etc. could read as just another `add`-related option in the
inputs list (alongside `add_options`, `commit_options`, `push_options`).
Suffix all eight hook inputs with `_hook` to disambiguate them from the
existing option-category inputs.

Internal helper still calls `_run_hook "before_add" ...` so the
`::debug::Running before_add hook` log line is unchanged.
The first arg to `_run_hook` (used as the event name in the debug log)
also gets the `_hook` suffix so the log line matches the action input
name exactly. Drop the redundant trailing 'hook' word from the log
message, so it now reads e.g. '::debug::Running before_add_hook' instead
of '::debug::Running before_add hook'.
@stefanzweifel stefanzweifel self-assigned this Jun 28, 2026
@stefanzweifel
stefanzweifel marked this pull request as ready for review June 28, 2026 08:31
@stefanzweifel
stefanzweifel merged commit 9f6c933 into master Jun 28, 2026
2 checks passed
@stefanzweifel
stefanzweifel deleted the git-auto-commit-hooks branch June 28, 2026 08:52
ajgon pushed a commit to deedee-ops/schemas that referenced this pull request Jun 28, 2026
… (v7.1.0 ➔ v7.2.0) (#6)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [stefanzweifel/git-auto-commit-action](https://github.com/stefanzweifel/git-auto-commit-action) | action | minor | `v7.1.0` → `v7.2.0` |

---

### Release Notes

<details>
<summary>stefanzweifel/git-auto-commit-action (stefanzweifel/git-auto-commit-action)</summary>

### [`v7.2.0`](https://github.com/stefanzweifel/git-auto-commit-action/blob/HEAD/CHANGELOG.md#v720---2026-06-28)

[Compare Source](stefanzweifel/git-auto-commit-action@v7.1.0...v7.2.0)

##### Added

- Add hooks to run shell snippets around git operations ([#&#8203;411](stefanzweifel/git-auto-commit-action#411)) [@&#8203;stefanzweifel](https://github.com/@&#8203;stefanzweifel)
- Emit warning for pull\_request\_target trigger usage ([#&#8203;410](stefanzweifel/git-auto-commit-action#410)) [@&#8203;stefanzweifel](https://github.com/@&#8203;stefanzweifel)

##### Fixed

- docs(action): fix input and output descriptions in action.yml ([#&#8203;406](stefanzweifel/git-auto-commit-action#406)) [@&#8203;kranthipoturaju](https://github.com/@&#8203;kranthipoturaju)
- docs: fix typos, grammar, and formatting across markdown files ([#&#8203;408](stefanzweifel/git-auto-commit-action#408)) [@&#8203;kranthipoturaju](https://github.com/@&#8203;kranthipoturaju)
- docs: fix broken and redirecting URLs in README.md ([#&#8203;407](stefanzweifel/git-auto-commit-action#407)) [@&#8203;kranthipoturaju](https://github.com/@&#8203;kranthipoturaju)
- README: clearify meaning of the repository field ([#&#8203;404](stefanzweifel/git-auto-commit-action#404)) [@&#8203;gucio321](https://github.com/@&#8203;gucio321)

##### Dependency Updates

- Bump actions/checkout from 6 to 7 ([#&#8203;409](stefanzweifel/git-auto-commit-action#409)) \[@&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)]\(<https://github.com/@&#8203;[dependabot[bot>]]\(<https://github.com/apps/dependabot>))
- Bump release-drafter/release-drafter from 6 to 7 ([#&#8203;403](stefanzweifel/git-auto-commit-action#403)) \[@&#8203;[dependabot\[bot\]](https://github.com/apps/dependabot)]\(<https://github.com/@&#8203;[dependabot[bot>]]\(<https://github.com/apps/dependabot>))

</details>

---

### Configuration

📅 **Schedule**: (in timezone Europe/Warsaw)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4yNDUuMCIsInVwZGF0ZWRJblZlciI6IjQzLjI0NS4wIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->

Reviewed-on: https://git.ajgon.casa/deedee/schemas/pulls/6
@ro0NL

ro0NL commented Jul 2, 2026

Copy link
Copy Markdown

Nice. I think we solved concurrency issues using before_push_hook

error: failed to push some refs
hint: Updates were rejected because the tip of your current branch is behind

fix:

before_push_hook: git -c user.name="${INPUT_COMMIT_USER_NAME}" -c user.email="${INPUT_COMMIT_USER_EMAIL}" pull --rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants