Add RebaseOpen() service to wrapper

This commit is contained in:
ezwiebel 2016-09-06 14:15:10 +10:00
parent b2d71f4fbc
commit e00b0831aa
2 changed files with 34 additions and 2 deletions

View File

@ -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);
*/

View File

@ -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)