Skip to content
Merged
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
10 changes: 4 additions & 6 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@

- id: prepare-commit-msg
name: prepare commit message
description: add the JIRA ID found in the branch name in case it is missing from the commit message
entry: git_message_hook
args: [--prepare]
description: add the branch JIRA ID to the subject or, with --issue-trailer, an Issue trailer
entry: git_message_hook --prepare
language: python
stages: [prepare-commit-msg]

- id: check-commit-msg
name: check commit message
description: check the commit message for a valid JIRA ID
entry: git_message_hook
args: [--check]
description: check for a valid JIRA ID in the subject or, with --issue-trailer, an Issue trailer
entry: git_message_hook --check
language: python
stages: [commit-msg]
73 changes: 67 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,78 @@ Only enable the optional PyTorch check with `--check-pytorch` when required.
which can reject recipes whose constraints apply to a different platform.

### `prepare-commit-msg`
Adds the JIRA ID found in the branch name in case it is missing from the commit message.
Adds the JIRA ID found in the branch name in case it is missing from the commit
message, including during a rebase or cherry-pick. Existing JIRA IDs in replayed
commit messages are preserved.

### `check-commit-message`
### `check-commit-msg`
Checks that the branch name or the commit message starts with a reference to JIRA,
and if the message meets the minimum required length for the summary line. Also checks
that the JIRA ID in the commit message is consistent with the one extracted from the
branch name (if any).
and that the message meets the minimum required length for the summary line. Also
checks that the JIRA ID in the commit message is consistent with the one extracted
from the branch name (if any), except during a rebase or cherry-pick, when replayed
commit messages may have a different JIRA ID. During a rebase, a JIRA ID is also
optional when neither the branch nor the commit message supplies one. Minimum
summary length is not enforced during rebases or cherry-picks.

By default, the message hooks use a JIRA ID at the beginning of the commit subject.
To use an `Issue: GA-1234` footer trailer instead, enable `--issue-trailer` on both
hooks:

```yaml
hooks:
- id: prepare-commit-msg
args: [--issue-trailer]
- id: check-commit-msg
args: [--issue-trailer]
```

For example, a prepared message would be:

```text
Fix the coordinate transformation

Explain the change here.

Issue: GA-1234
```

In this mode, preparation leaves the subject unchanged and adds the branch's JIRA
ID as an Issue trailer only when no Issue trailer already exists. Existing trailers
and the message body are retained. Trailers form the final block of
colon-separated fields, separated from the subject or body by a blank line;
indented continuation lines are supported. An ID in the subject, body, `#` template
comments, or patch text does not count as an Issue trailer.

The hooks handle trailers directly in Python, without starting Git. They use fixed
`Issue:` syntax and do not read Git's `trailer.*` configuration settings for custom
keys, separators, insertion order, duplicate handling, or commands that generate
trailer values. No Git trailer configuration is required. Those settings still
apply when using Git's own trailer commands.

Validation uses Issue trailers instead of subject prefixes. Each Issue trailer must
contain a valid JIRA ID, and IDs must match the branch's ID when one exists, except
during rebases or cherry-picks. As in subject mode, the branch's ID alone can
satisfy the JIRA requirement. Summary length is measured on the subject without
counting trailer text. The existing rebase and cherry-pick exceptions apply in
both modes.

### Autosquash commits
The Git prefixes `fixup!`, `squash!`, and `amend!` identify autosquash targets,
including when those prefixes are nested. The hooks preserve the exact target
subject so that `git rebase --autosquash` can still match the original commit. In
header mode, no JIRA ID is inserted into these subjects; the branch's JIRA ID can
satisfy validation, and an existing ID after the bang prefixes is still parsed
and checked for consistency. In trailer mode, validation continues to use the
Issue trailer or branch, and a missing Issue trailer can still be added without
changing the subject.

Autosquash targets are exempt from the minimum summary length because they can
reference short original subjects or commit hashes. JIRA presence and consistency
checks still apply, subject to the existing rebase and cherry-pick exceptions.

## Usage

Example of `.pre-commit-config.yamnl`:
Example of `.pre-commit-config.yaml`:

```yaml
repos:
Expand Down
Loading
Loading