summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rebase.go20
-rw-r--r--rebase_test.go16
2 files changed, 34 insertions, 2 deletions
diff --git a/rebase.go b/rebase.go
index ab112c0..a51b7ce 100644
--- a/rebase.go
+++ b/rebase.go
@@ -81,6 +81,25 @@ func (r *Repository) RebaseInit(branch *AnnotatedCommit, upstream *AnnotatedComm
return newRebaseFromC(ptr), nil
}
+//RebaseOpen opens an existing rebase that was previously started by either an invocation of git_rebase_init or by another client.
+func (r *Repository) RebaseOpen(opts *RebaseOptions) (*Rebase, error) {
+ runtime.LockOSThread()
+ defer runtime.UnlockOSThread()
+
+ //TODO : use real rebase_options
+ if opts != nil {
+ return nil, errors.New("RebaseOptions Not implemented yet, use nil for default opts")
+ }
+
+ var ptr *C.git_rebase
+ err := C.git_rebase_open(&ptr, r.ptr, nil)
+ if err < 0 {
+ return nil, MakeGitError(err)
+ }
+
+ return newRebaseFromC(ptr), nil
+}
+
// OperationAt gets the rebase operation specified by the given index.
func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
operation := C.git_rebase_operation_byindex(rebase.ptr, C.size_t(index))
@@ -183,6 +202,5 @@ func newRebaseFromC(ptr *C.git_rebase) *Rebase {
/* TODO -- Add last wrapper services and manage rebase_options
int git_rebase_init_options(git_rebase_options *opts, unsigned int version);
-int git_rebase_open(git_rebase **out, git_repository *repo, const git_rebase_options *opts);
*/
diff --git a/rebase_test.go b/rebase_test.go
index e97a1a7..745297e 100644
--- a/rebase_test.go
+++ b/rebase_test.go
@@ -87,8 +87,14 @@ func TestRebaseNoConflicts(t *testing.T) {
defer cleanupTestRepo(t, repo)
seedTestRepo(t, repo)
+ // Try to open existing rebase
+ oRebase, err := repo.RebaseOpen(nil)
+ if err == nil {
+ t.Fatal("Did not expect to find a rebase in progress")
+ }
+
// Setup a repo with 2 branches and a different tree
- err := setupRepoForRebase(repo, masterCommit, branchName)
+ err = setupRepoForRebase(repo, masterCommit, branchName)
checkFatal(t, err)
// Create several commits in emile
@@ -102,6 +108,14 @@ func TestRebaseNoConflicts(t *testing.T) {
checkFatal(t, err)
defer rebase.Free()
+ // Open existing rebase
+ oRebase, err = repo.RebaseOpen(nil)
+ checkFatal(t, err)
+ defer oRebase.Free()
+ if oRebase == nil {
+ t.Fatal("Expected to find an existing rebase in progress")
+ }
+
// Finish the rebase properly
err = rebase.Finish()
checkFatal(t, err)