Add trailer support for commit creation#2116
Open
Krishnachaitanyakc wants to merge 1 commit intogitpython-developers:mainfrom
Open
Add trailer support for commit creation#2116Krishnachaitanyakc wants to merge 1 commit intogitpython-developers:mainfrom
Krishnachaitanyakc wants to merge 1 commit intogitpython-developers:mainfrom
Conversation
Add a `trailers` parameter to `Commit.create_from_tree()` and `IndexFile.commit()` that allows appending trailer key-value pairs (e.g. Signed-off-by, Issue) to the commit message at creation time. Trailers can be passed as either a dict or a list of (key, value) tuples, the latter being useful when duplicate keys are needed. The implementation uses `git interpret-trailers` for proper formatting, consistent with the existing trailer parsing in `Commit.trailers_list`. Closes gitpython-developers#1998
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
trailersparameter toCommit.create_from_tree()andIndexFile.commit()enabling trailer creation (e.g.Signed-off-by,Issue) when committing programmaticallydictor a list of(key, value)tuples (for duplicate keys like multipleSigned-off-by)git interpret-trailersfor formatting, consistent with existing trailer parsing inCommit.trailers_listCloses #1998
Motivation
GitPython already supports parsing trailers from existing commits, but did not support adding them when creating new commits. The
git commitCLI supports this via--trailer, e.g.:This change brings equivalent functionality to GitPython's Python API.
Usage
Test plan
test_create_from_tree_with_trailers_dict- verifies dict-based trailer creation and round-trip parsingtest_create_from_tree_with_trailers_list- verifies list-of-tuples trailer creation with duplicate keystest_index_commit_with_trailers- verifiesIndexFile.commit()passes trailers through correctly