diff --git a/pkg/git/init.go b/pkg/git/init.go index 5861e115e..894546928 100644 --- a/pkg/git/init.go +++ b/pkg/git/init.go @@ -15,7 +15,9 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error { if err != nil { return fmt.Errorf("git init: %s", err) } - MasterToMain(repo) + if err = SwitchToMain(repo); err != nil { + return fmt.Errorf("git branch rename: %s", err) + } log.Debugf("initialised new git repo in %s", repoPath) if commit { @@ -46,20 +48,21 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error { return nil } -func MasterToMain(repo *git.Repository) { +func SwitchToMain(repo *git.Repository) error { // Create and set the 'main' branch as default ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main")) if err := repo.Storer.SetReference(ref); err != nil { - log.Fatalf("Failed to set 'main' as default branch: %v", err) + return fmt.Errorf("set reference: %s", err) } // Update the repository configuration cfg, err := repo.Config() if err != nil { - log.Fatalf("Failed to get repository config: %v", err) + return fmt.Errorf("repo config: %s", err) } cfg.Init.DefaultBranch = "main" if err := repo.SetConfig(cfg); err != nil { - log.Fatalf("Failed to update repository config: %v", err) + return fmt.Errorf("repo set config: %s", err) } - fmt.Println("Set 'main' as the default branch.") + log.Debug("set 'main' as the default branch.") + return nil }