(repo *Repository, branch string, rebaseOpts *RebaseOptions)
| 357 | } |
| 358 | |
| 359 | func performRebaseOnto(repo *Repository, branch string, rebaseOpts *RebaseOptions) (*Rebase, error) { |
| 360 | master, err := repo.LookupBranch(branch, BranchLocal) |
| 361 | if err != nil { |
| 362 | return nil, err |
| 363 | } |
| 364 | defer master.Free() |
| 365 | |
| 366 | onto, err := repo.AnnotatedCommitFromRef(master.Reference) |
| 367 | if err != nil { |
| 368 | return nil, err |
| 369 | } |
| 370 | defer onto.Free() |
| 371 | |
| 372 | // Init rebase |
| 373 | rebase, err := repo.InitRebase(nil, nil, onto, rebaseOpts) |
| 374 | if err != nil { |
| 375 | return nil, err |
| 376 | } |
| 377 | |
| 378 | // Check no operation has been started yet |
| 379 | rebaseOperationIndex, err := rebase.CurrentOperationIndex() |
| 380 | if rebaseOperationIndex != RebaseNoOperation && err != ErrRebaseNoOperation { |
| 381 | return nil, errors.New("No operation should have been started yet") |
| 382 | } |
| 383 | |
| 384 | // Iterate in rebase operations regarding operation count |
| 385 | opCount := int(rebase.OperationCount()) |
| 386 | for op := 0; op < opCount; op++ { |
| 387 | operation, err := rebase.Next() |
| 388 | if err != nil { |
| 389 | return nil, err |
| 390 | } |
| 391 | |
| 392 | // Check operation index is correct |
| 393 | rebaseOperationIndex, err = rebase.CurrentOperationIndex() |
| 394 | if int(rebaseOperationIndex) != op { |
| 395 | return nil, errors.New("Bad operation index") |
| 396 | } |
| 397 | if !operationsAreEqual(rebase.OperationAt(uint(op)), operation) { |
| 398 | return nil, errors.New("Rebase operations should be equal") |
| 399 | } |
| 400 | |
| 401 | // Get current rebase operation created commit |
| 402 | commit, err := repo.LookupCommit(operation.Id) |
| 403 | if err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | defer commit.Free() |
| 407 | |
| 408 | // Apply commit |
| 409 | err = rebase.Commit(operation.Id, signature(), signature(), commit.Message()) |
| 410 | if err != nil { |
| 411 | return nil, err |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return rebase, nil |
| 416 | } |
no test coverage detected
searching dependent graphs…