diff --git a/commands/project/create/project_create.go b/commands/project/create/project_create.go index 3d9d70bd..3c92d1fb 100644 --- a/commands/project/create/project_create.go +++ b/commands/project/create/project_create.go @@ -76,13 +76,28 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er if err != nil { return err } + apiClient, err := f.HttpClient() + if err != nil { + return err + } if len(args) == 1 { - projectPath = args[0] - if strings.Contains(projectPath, "/") { - pp := strings.Split(projectPath, "/") - projectPath = pp[1] - namespace = pp[0] + var host string + host, namespace, projectPath = projectPathFromArgs(args) + if host != "" { + cfg, _ := f.Config() + client, err := api.NewClientWithCfg(host, cfg, false) + if err != nil { + return err + } + apiClient = client.Lab() + } + user, err := api.CurrentUser(apiClient) + if err != nil { + return err + } + if user.Username == namespace { + namespace = "" } } else { projectPath, err = git.ToplevelDir() @@ -93,11 +108,6 @@ func runCreateProject(cmd *cobra.Command, args []string, f *cmdutils.Factory) er isPath = true } - apiClient, err := f.HttpClient() - if err != nil { - return err - } - group, err := cmd.Flags().GetString("group") if err != nil { return fmt.Errorf("could not parse group flag: %v", err) @@ -254,3 +264,14 @@ func initialiseRepo(projectPath, remoteURL string) error { } return nil } + +func projectPathFromArgs(args []string) (host, namespace, project string) { + project = args[0] + if strings.Contains(project, "/") { + pp, _ := glrepo.FromFullName(project) + host = pp.RepoHost() + project = pp.RepoName() + namespace = pp.RepoNamespace() + } + return +}