Merge pull request #3807 from camillesf/nonempty_fork_org

repo fork: check that --org is not the empty string
This commit is contained in:
Nate Smith 2021-06-28 11:16:30 -07:00 committed by GitHub
commit c33b7d0c22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 10 deletions

View file

@ -83,20 +83,20 @@ 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")}
} 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 {

View file

@ -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",