Closes #693: wrap libgit2's rebase API - #1483
Merged
Merged
Conversation
Add Repository.rebase_init() and Repository.rebase_open(), returning a Rebase object that drives git_rebase_next/commit/finish/abort through the Python iterator protocol, plus RebaseOperation and enums.RebaseOperationType. The options expose inmemory, quiet, rewrite_notes_ref, the merge favor/flags/file_flags knobs, checkout strategy, and conflict marker labels. Also fix enums.CheckoutStrategy.CONFLICT_STYLE_ZDIFF3, which was mistakenly bound to the DIFF3 constant. The tests cover the native API (clean replay, hunk-level conflict markers, custom labels, diff3 style, unresolved-conflict and already-applied errors, abort, in-memory rebase, fast-forward via finish, resuming with rebase_open) and keep a "manual rebase" implementation built from pygit2 primitives as a behavioral baseline to compare edge cases against. Assisted-by: Claude Fable 5
Callers previously could not tell GIT_EAPPLIED apart from any other error: pygit2 exceptions don't carry the libgit2 error code, so driving a rebase loop meant guessing which GitError is safe to skip. Mirror `git rebase`, which skips patches that are already present upstream, by returning None from commit() in that case. Unresolved conflicts still raise GitError. Also link the 1.20.0 changelog entries to the PR. Assisted-by: Claude Fable 5
Member
|
Merged, thanks! |
Contributor
|
@ambv hey, thanks for this! Do you have any public use examples of this API, anything to share? |
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.
This adds
Repository.rebase_init()andRepository.rebase_open(), returning aRebaseobject that you iterate over and call methods on likecommit/finish/abort. The options expose in-memory, quiet, rewrite_notes_ref, the merge favor/flags/file_flags knobs, checkout strategy, and conflict marker labels.Sorry the PR is pretty big, but it closes a major gap in pygit2 and I promised to implement it last year 😅
I extended the cffi bindings here, as I know the project is moving away from the manual C extension. I based the bindings on libgit2 1.9.6, but AFAICT there's been no changes to the rebase API in 2.x so far.
I also fixed
enums.CheckoutStrategy.CONFLICT_STYLE_ZDIFF3, which was mistakenly bound to theDIFF3constant.The tests cover the native API, but I also added a "manual rebase" implementation built from pygit2 primitives that I was using before as a behavioral baseline to compare edge cases against. This might prove useful when you're adopting libgit2 2.x. Plus it's extra coverage for the library.