@@ -790,13 +790,6 @@ func migratePullRequests(ctx context.Context, githubPath, gitlabPath []string, p
790790 continue
791791 }
792792
793- // Starting with a merge commit is _probably_ wrong
794- if startCommit .NumParents () > 1 {
795- sendErr (fmt .Errorf ("start commit %s for merge request %d has %d parents" , mergeRequestCommits [0 ].ShortID , mergeRequest .IID , startCommit .NumParents ()))
796- failureCount ++
797- continue
798- }
799-
800793 if startCommit .NumParents () == 0 {
801794 // Orphaned commit, start with an empty branch
802795 // TODO: this isn't working as hoped, try to figure this out. in the meantime, we'll skip MRs from orphaned branches
@@ -806,15 +799,23 @@ func migratePullRequests(ctx context.Context, githubPath, gitlabPath []string, p
806799 sendErr (fmt .Errorf ("start commit %s for merge request %d has no parents" , mergeRequestCommits [0 ].ShortID , mergeRequest .IID ))
807800 continue
808801 } else {
809- // Branch out from parent commit
810- logger .Trace ("inspecting start commit parent" , "name" , gitlabPath [1 ], "group" , gitlabPath [0 ], "project_id" , project .ID , "merge_request_id" , mergeRequest .IID , "sha" , mergeRequestCommits [0 ].ShortID )
811- startCommitParent , err := startCommit .Parent (0 )
812- if err != nil {
813- sendErr (fmt .Errorf ("loading parent commit: %s" , err ))
814- failureCount ++
802+ // Sometimes we will be starting from a merge commit, so look for a suitable parent commit to branch out from
803+ var startCommitParent * object.Commit
804+ for i := 0 ; i < startCommit .NumParents (); i ++ {
805+ logger .Trace ("inspecting start commit parent" , "name" , gitlabPath [1 ], "group" , gitlabPath [0 ], "project_id" , project .ID , "merge_request_id" , mergeRequest .IID , "sha" , mergeRequestCommits [0 ].ShortID )
806+ startCommitParent , err = startCommit .Parent (0 )
807+ if err != nil {
808+ sendErr (fmt .Errorf ("loading parent commit: %s" , err ))
809+ }
810+
815811 continue
816812 }
817813
814+ if startCommitParent == nil {
815+ sendErr (fmt .Errorf ("identifying suitable parent of start commit %s for merge request %d" , mergeRequestCommits [0 ].ShortID , mergeRequest .IID ))
816+ failureCount ++
817+ }
818+
818819 logger .Trace ("creating target branch for merged/closed merge request" , "name" , gitlabPath [1 ], "group" , gitlabPath [0 ], "project_id" , project .ID , "merge_request_id" , mergeRequest .IID , "branch" , mergeRequest .TargetBranch , "sha" , startCommitParent .Hash )
819820 if err = worktree .Checkout (& git.CheckoutOptions {
820821 Create : true ,
0 commit comments