summaryrefslogtreecommitdiff
path: root/rebase.go
diff options
context:
space:
mode:
authorPatrick Steinhardt <[email protected]>2022-02-24 14:27:26 +0100
committerGitHub <[email protected]>2022-02-24 05:27:26 -0800
commite7d1b2b69fbe476c75a00cf8dcda284337facb50 (patch)
tree7d90ef52471591ae21a3a36b730f0e864487a304 /rebase.go
parentc598ea5718d76bd08475172367236e27f1ed7dbf (diff)
rebase: Add wrapper for `git_rebase_inmemory_index()` (#900)
* rebase: Fix missing initialization of the repo pointer While the `Rebase` structure has a pointer to the repository the rebase is creatde in, this pointer isn't ever initialized. Fix this. * rebase: Add wrapper for `git_rebase_inmemory_index()` Add a new wrapper for `git_rebase_inmemory_index()`, which can be used to retrieve the index for an in-memory rebase. Co-authored-by: Patrick Steinhardt <[email protected]>
Diffstat (limited to 'rebase.go')
-rw-r--r--rebase.go29
1 files changed, 25 insertions, 4 deletions
diff --git a/rebase.go b/rebase.go
index 58c0b6f..b9c94fd 100644
--- a/rebase.go
+++ b/rebase.go
@@ -318,7 +318,7 @@ func (r *Repository) InitRebase(branch *AnnotatedCommit, upstream *AnnotatedComm
return nil, MakeGitError(ret)
}
- return newRebaseFromC(ptr, cOpts), nil
+ return newRebaseFromC(ptr, r, cOpts), nil
}
// OpenRebase opens an existing rebase that was previously started by either an invocation of InitRebase or by another client.
@@ -340,7 +340,7 @@ func (r *Repository) OpenRebase(opts *RebaseOptions) (*Rebase, error) {
return nil, MakeGitError(ret)
}
- return newRebaseFromC(ptr, cOpts), nil
+ return newRebaseFromC(ptr, r, cOpts), nil
}
// OperationAt gets the rebase operation specified by the given index.
@@ -392,6 +392,27 @@ func (rebase *Rebase) Next() (*RebaseOperation, error) {
return newRebaseOperationFromC(ptr), nil
}
+// InmemoryIndex gets the index produced by the last operation, which is the
+// result of `Next()` and which will be committed by the next invocation of
+// `Commit()`. This is useful for resolving conflicts in an in-memory rebase
+// before committing them.
+//
+// This is only applicable for in-memory rebases; for rebases within a working
+// directory, the changes were applied to the repository's index.
+func (rebase *Rebase) InmemoryIndex() (*Index, error) {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ var ptr *C.git_index
+ err := C.git_rebase_inmemory_index(&ptr, rebase.ptr)
+ runtime.KeepAlive(rebase)
+ if err < 0 {
+ return nil, MakeGitError(err)
+ }
+
+ return newIndexFromC(ptr, rebase.r), nil
+}
+
// Commit commits the current patch.
// You must have resolved any conflicts that were introduced during the patch application from the Next() invocation.
func (rebase *Rebase) Commit(ID *Oid, author, committer *Signature, message string) error {
@@ -457,8 +478,8 @@ func (r *Rebase) Free() {
freeRebaseOptions(r.options)
}
-func newRebaseFromC(ptr *C.git_rebase, opts *C.git_rebase_options) *Rebase {
- rebase := &Rebase{ptr: ptr, options: opts}
+func newRebaseFromC(ptr *C.git_rebase, repo *Repository, opts *C.git_rebase_options) *Rebase {
+ rebase := &Rebase{ptr: ptr, r: repo, options: opts}
runtime.SetFinalizer(rebase, (*Rebase).Free)
return rebase
}