From b389ca1777df8963557bde8b4953f0829cff09e3 Mon Sep 17 00:00:00 2001 From: Wilson Marco Sales Moncayo Date: Sat, 2 Oct 2021 17:55:47 -0300 Subject: [PATCH] add remoteName flag to 'create project' command By default glab would add the created project's repository URL to the a remote named 'origin', which fails when there already is such a remote. This commit adds the option to specify a remote name for glab to add in the local git repository, so that the user may specify a different one, should 'origin' be already taken. Closes #803. --- commands/project/create/project_create.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/project/create/project_create.go b/commands/project/create/project_create.go index 31d84016..f216dbaf 100644 --- a/commands/project/create/project_create.go +++ b/commands/project/create/project_create.go @@ -48,6 +48,7 @@ func NewCmdCreate(f *cmdutils.Factory) *cobra.Command { projectCreateCmd.Flags().StringP("group", "g", "", "Namespace/group for the new project (defaults to the current user’s namespace)") projectCreateCmd.Flags().StringP("description", "d", "", "Description of the new project") projectCreateCmd.Flags().String("defaultBranch", "", "Default branch of the project. If not provided, `master` by default.") + projectCreateCmd.Flags().String("remoteName", "origin", "Remote name for the Git repository you're in. If not provided, `origin` by default.") projectCreateCmd.Flags().StringArrayP("tag", "t", []string{}, "The list of tags for the project.") projectCreateCmd.Flags().Bool("internal", false, "Make project internal: visible to any authenticated user (default)") projectCreateCmd.Flags().BoolP("private", "p", false, "Make project private: visible only to project members") @@ -72,6 +73,10 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er if err != nil { return err } + remoteName, err := cmd.Flags().GetString("remoteName") + if err != nil { + return err + } err = initGit(defaultBranch) if err != nil { return err @@ -175,7 +180,7 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er protocol, _ := cfg.Get(webURL.Host, "git_protocol") remote := glrepo.RemoteURL(project, protocol) - _, err = git.AddRemote("origin", remote) + _, err = git.AddRemote(remoteName, remote) if err != nil { return err }