Skip to content

Commit 5c0d7ee

Browse files
committed
Iterate branches and explicitly push them
1 parent be115c5 commit 5c0d7ee

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

main.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,25 @@ func migrateProject(ctx context.Context, proj []string) error {
707707
return fmt.Errorf("adding github remote: %v", err)
708708
}
709709

710-
logger.Debug("force-pushing to GitHub repository", "name", gitlabPath[1], "group", gitlabPath[0], "url", githubUrl)
710+
logger.Debug("determining branches to push", "name", gitlabPath[1], "group", gitlabPath[0], "url", githubUrl)
711+
branches, err := repo.Branches()
712+
if err != nil {
713+
return fmt.Errorf("retrieving branches: %v", err)
714+
}
715+
716+
refSpecs := make([]config.RefSpec, 0)
717+
if err = branches.ForEach(func(ref *plumbing.Reference) error {
718+
refSpecs = append(refSpecs, config.RefSpec(fmt.Sprintf("%[1]s:%[1]s", ref.Name())))
719+
return nil
720+
}); err != nil {
721+
return fmt.Errorf("parsing branches: %v", err)
722+
}
723+
724+
logger.Debug("force-pushing branches to GitHub repository", "name", gitlabPath[1], "group", gitlabPath[0], "url", githubUrl, "count", len(refSpecs))
711725
if err = repo.PushContext(ctx, &git.PushOptions{
712726
RemoteName: "github",
713727
Force: true,
728+
RefSpecs: refSpecs,
714729
//Prune: true, // causes error, attempts to delete main branch
715730
}); err != nil {
716731
if errors.Is(err, git.NoErrAlreadyUpToDate) {
@@ -720,7 +735,7 @@ func migrateProject(ctx context.Context, proj []string) error {
720735
}
721736
}
722737

723-
logger.Debug("pushing tags to GitHub repository", "name", gitlabPath[1], "group", gitlabPath[0], "url", githubUrl)
738+
logger.Debug("force-pushing tags to GitHub repository", "name", gitlabPath[1], "group", gitlabPath[0], "url", githubUrl)
724739
if err = repo.PushContext(ctx, &git.PushOptions{
725740
RemoteName: "github",
726741
Force: true,

0 commit comments

Comments
 (0)