From 54b86c70937f4cf9b75877fa31127a2cf9c796a3 Mon Sep 17 00:00:00 2001 From: camille folch Date: Tue, 8 Jun 2021 20:22:57 -0300 Subject: [PATCH 1/2] repo fork: check that --org is not the empty string As it is already being done for --remote-name, except in this case the default is the empty string. --- pkg/cmd/repo/fork/fork.go | 4 ++++ pkg/cmd/repo/fork/fork_test.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/pkg/cmd/repo/fork/fork.go b/pkg/cmd/repo/fork/fork.go index a441b1af5..36deda843 100644 --- a/pkg/cmd/repo/fork/fork.go +++ b/pkg/cmd/repo/fork/fork.go @@ -83,6 +83,10 @@ Additional 'git clone' flags can be passed in by listing them after '--'.`, opts.GitArgs = args[1:] } + if cmd.Flags().Changed("org") && opts.Organization == "" { + return &cmdutil.FlagError{Err: errors.New("--org cannot be blank")} + } + if opts.RemoteName == "" { return &cmdutil.FlagError{Err: errors.New("--remote-name cannot be blank")} } diff --git a/pkg/cmd/repo/fork/fork_test.go b/pkg/cmd/repo/fork/fork_test.go index 914f60af8..1eb42943d 100644 --- a/pkg/cmd/repo/fork/fork_test.go +++ b/pkg/cmd/repo/fork/fork_test.go @@ -120,6 +120,12 @@ func TestNewCmdFork(t *testing.T) { Organization: "batmanshome", }, }, + { + name: "empty org", + cli: " --org=''", + wantErr: true, + errMsg: "--org cannot be blank", + }, { name: "git flags in wrong place", cli: "--depth 1 OWNER/REPO", From 568f4e4ee00a2ad6cce26bc87fea19bf9d938733 Mon Sep 17 00:00:00 2001 From: camille folch Date: Tue, 8 Jun 2021 20:26:22 -0300 Subject: [PATCH 2/2] Minor refactoring for readability in NewCmdFork's runE --- pkg/cmd/repo/fork/fork.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/pkg/cmd/repo/fork/fork.go b/pkg/cmd/repo/fork/fork.go index 36deda843..a83000e0a 100644 --- a/pkg/cmd/repo/fork/fork.go +++ b/pkg/cmd/repo/fork/fork.go @@ -89,18 +89,14 @@ Additional 'git clone' flags can be passed in by listing them after '--'.`, if opts.RemoteName == "" { return &cmdutil.FlagError{Err: errors.New("--remote-name cannot be blank")} + } else if !cmd.Flags().Changed("remote-name") { + opts.Rename = true // Any existing 'origin' will be renamed to upstream } - if promptOk && !cmd.Flags().Changed("clone") { - opts.PromptClone = true - } - - if promptOk && !cmd.Flags().Changed("remote") { - opts.PromptRemote = true - } - - if !cmd.Flags().Changed("remote-name") { - opts.Rename = true + if promptOk { + // We can prompt for these if they were not specified. + opts.PromptClone = !cmd.Flags().Changed("clone") + opts.PromptRemote = !cmd.Flags().Changed("remote") } if runF != nil {