Repository navigation
Commit 30bcf67
committed
fix(commit): stop treating
`Commit._interpret_trailers`, which backs `Commit.trailers_list`,
`Commit.trailers_dict` and the `trailers` argument of
`Commit.create_from_tree()` and `IndexFile.commit()`, ran
`git interpret-trailers` without `--no-divider`. In that mode
interpret-trailers reads its input as a `git format-patch` e-mail: the
first line starting with `---` followed by whitespace begins the patch,
and only the text above it is searched for trailers or receives new ones.
Git does not apply that rule to commit messages. `%(trailers)` in
`pretty.c` sets `no_divider`, `git commit --trailer` runs
`interpret-trailers --no-divider` (`amend_file_with_trailers()`), and
`trailer_iterator_init()`, which the sign-off check in `sequencer.c`
uses, sets it as well. Commit messages are chosen by whoever authored
the commit, so GitPython and Git disagreed about the trailers of the
same commit, on both backends:
- Dependabot commits put a `---` line before their YAML metadata and sign
off below it. `trailers_list` returned `[]` for them, including the
Dependabot commits in this repository's history, while
`git log --format=%(trailers)` reports
`Signed-off-by: dependabot[bot] <support@github.com>`.
- A paragraph such as `Reviewed-by: Maintainer <m@example.com>` followed
by `---` and more text was reported as a trailer, although Git treats it
as body text and reports no trailers for that commit.
- `create_from_tree()` with the message `Subject\n\nBody\n---\nNotes\n`
and a `Signed-off-by` trailer inserted the trailer above the `---` line,
where `git commit --trailer` appends it after `Notes`.
Pass `--no-divider` in `_interpret_trailers`, so the parse and add paths
treat their input as the commit message it is. Messages without such a
`---` line are unaffected. `interpret_trailers` has no Gix handler, so
the change covers both backends.
Validation on macOS with CPython 3.13.17, Git 2.54.0 and GixPython 0.3.0:
- `test_trailers_ignore_patch_divider` and
`test_create_from_tree_appends_trailers_after_patch_divider` in
`test/test_commit.py` fail before the change and pass after it on both
backends.
- 300 randomized messages built from trailer lines, `---` variants,
comments and body text were committed and `trailers_list` was compared
with `git log --format=%(trailers:only,unfold)` for the same commit.
Before the change 52 disagreed on the CLI backend; after it none
disagreed on either backend (300 messages each).
- Full suite: 2207 passed, 155 skipped, 1 xfailed on the CLI backend;
2310 passed, 52 skipped, 1 xfailed on the Gix backend.
- Ruff check and format (pre-commit), mypy, `basedpyright --warnings` and
`git diff --check` pass.
Agent-Model: claude-opus-5-5--- as a patch divider for trailers1 parent 029964a commit 30bcf67
3 files changed
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
100 | 105 | | |
101 | 106 | | |
102 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
612 | 612 | | |
613 | 613 | | |
614 | 614 | | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
615 | 619 | | |
616 | 620 | | |
617 | 621 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
872 | 872 | | |
873 | 873 | | |
874 | 874 | | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
875 | 890 | | |
876 | 891 | | |
877 | 892 | | |
| |||
950 | 965 | | |
951 | 966 | | |
952 | 967 | | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
953 | 984 | | |
954 | 985 | | |
955 | 986 | | |
| |||
0 commit comments