Merge pull request #396 from libgit2/cmn/rebase-no-operation
rebase: correct the return values for CurrentOperationIndex
This commit is contained in:
commit
2cff3f2ef4
22
rebase.go
22
rebase.go
|
@ -5,6 +5,7 @@ package git
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"runtime"
|
"runtime"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -25,6 +26,12 @@ const (
|
||||||
RebaseOperationExec RebaseOperationType = C.GIT_REBASE_OPERATION_EXEC
|
RebaseOperationExec RebaseOperationType = C.GIT_REBASE_OPERATION_EXEC
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Special value indicating that there is no currently active operation
|
||||||
|
var RebaseNoOperation uint = ^uint(0)
|
||||||
|
|
||||||
|
// Error returned if there is no current rebase operation
|
||||||
|
var ErrRebaseNoOperation = errors.New("o current rebase operation")
|
||||||
|
|
||||||
// RebaseOperation describes a single instruction/operation to be performed during the rebase.
|
// RebaseOperation describes a single instruction/operation to be performed during the rebase.
|
||||||
type RebaseOperation struct {
|
type RebaseOperation struct {
|
||||||
Type RebaseOperationType
|
Type RebaseOperationType
|
||||||
|
@ -154,18 +161,21 @@ func (rebase *Rebase) OperationAt(index uint) *RebaseOperation {
|
||||||
return newRebaseOperationFromC(operation)
|
return newRebaseOperationFromC(operation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentOperationIndex gets the index of the rebase operation that is currently being applied.
|
// CurrentOperationIndex gets the index of the rebase operation that is
|
||||||
// Returns an error if no rebase operation is currently applied.
|
// currently being applied. There is also an error returned for API
|
||||||
|
// compatibility.
|
||||||
func (rebase *Rebase) CurrentOperationIndex() (uint, error) {
|
func (rebase *Rebase) CurrentOperationIndex() (uint, error) {
|
||||||
runtime.LockOSThread()
|
runtime.LockOSThread()
|
||||||
defer runtime.UnlockOSThread()
|
defer runtime.UnlockOSThread()
|
||||||
|
|
||||||
operationIndex := int(C.git_rebase_operation_current(rebase.ptr))
|
var err error
|
||||||
if operationIndex == C.GIT_REBASE_NO_OPERATION {
|
operationIndex := uint(C.git_rebase_operation_current(rebase.ptr))
|
||||||
return 0, MakeGitError(C.GIT_REBASE_NO_OPERATION)
|
runtime.KeepAlive(rebase)
|
||||||
|
if operationIndex == RebaseNoOperation {
|
||||||
|
err = ErrRebaseNoOperation
|
||||||
}
|
}
|
||||||
|
|
||||||
return uint(operationIndex), nil
|
return uint(operationIndex), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// OperationCount gets the count of rebase operations that are to be applied.
|
// OperationCount gets the count of rebase operations that are to be applied.
|
||||||
|
|
|
@ -182,7 +182,7 @@ func performRebaseOnto(repo *Repository, branch string) (*Rebase, error) {
|
||||||
|
|
||||||
// Check no operation has been started yet
|
// Check no operation has been started yet
|
||||||
rebaseOperationIndex, err := rebase.CurrentOperationIndex()
|
rebaseOperationIndex, err := rebase.CurrentOperationIndex()
|
||||||
if err == nil {
|
if rebaseOperationIndex != RebaseNoOperation && err != ErrRebaseNoOperation {
|
||||||
return nil, errors.New("No operation should have been started yet")
|
return nil, errors.New("No operation should have been started yet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue