diff options
| author | ezwiebel <[email protected]> | 2016-08-07 17:31:42 +1000 |
|---|---|---|
| committer | ezwiebel <[email protected]> | 2016-08-07 18:09:33 +1000 |
| commit | 193b21398b76d602daabfef4d2462531c9aec410 (patch) | |
| tree | 367f899991b9a8405c470d7ae2ba267bab2b09f5 /rebase_test.go | |
| parent | e1f09497409bb8dea59d8312f1049267cee37544 (diff) | |
Add CurrentOperationIndex() and OperationAt(index uint) services to wrapper
Diffstat (limited to 'rebase_test.go')
| -rw-r--r-- | rebase_test.go | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/rebase_test.go b/rebase_test.go index dc5aeb3..e97a1a7 100644 --- a/rebase_test.go +++ b/rebase_test.go @@ -29,12 +29,12 @@ func TestRebaseAbort(t *testing.T) { // TEST repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) seedTestRepo(t, repo) // Setup a repo with 2 branches and a different tree err := setupRepoForRebase(repo, masterCommit, branchName) checkFatal(t, err) - defer cleanupTestRepo(t, repo) // Create several commits in emile for _, commit := range emileCommits { @@ -84,12 +84,12 @@ func TestRebaseNoConflicts(t *testing.T) { // TEST repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) seedTestRepo(t, repo) // Setup a repo with 2 branches and a different tree err := setupRepoForRebase(repo, masterCommit, branchName) checkFatal(t, err) - defer cleanupTestRepo(t, repo) // Create several commits in emile for _, commit := range emileCommits { @@ -154,25 +154,41 @@ func performRebaseOnto(repo *Repository, branch string) (*Rebase, error) { } defer onto.Free() + // Init rebase rebase, err := repo.RebaseInit(nil, nil, onto, nil) if err != nil { return nil, err } - opCount := int(rebase.OperationCount()) + // Check no operation has been started yet + if rebase.CurrentOperationIndex() != -1 { // -1 == GIT_REBASE_NO_OPERATION + return nil, errors.New("No operation should have been started yet") + } + // Iterate in rebase operations regarding operation count + opCount := int(rebase.OperationCount()) for op := 0; op < opCount; op++ { operation, err := rebase.Next() if err != nil { return nil, err } + // Check operation index is correct + if rebase.CurrentOperationIndex() != op { + return nil, errors.New("Bad operation index") + } + if !operationsAreEqual(rebase.OperationAt(uint(op)), operation) { + return nil, errors.New("Rebase operations should be equal") + } + + // Get current rebase operation created commit commit, err := repo.LookupCommit(operation.ID) if err != nil { return nil, err } defer commit.Free() + // Apply commit err = rebase.Commit(operation.ID, signature(), signature(), commit.Message()) if err != nil { return nil, err @@ -182,6 +198,10 @@ func performRebaseOnto(repo *Repository, branch string) (*Rebase, error) { return rebase, nil } +func operationsAreEqual(l, r *RebaseOperation) bool { + return l.Exec == r.Exec && l.Type == r.Type && l.ID.String() == r.ID.String() +} + func createBranch(repo *Repository, branch string) error { commit, err := headCommit(repo) if err != nil { |
