fix: error when --remote flag used with repo argument
When a repository argument is provided to `gh repo fork`, the command operates independently of the current local repository. Using --remote in this context is incompatible because there's no local repository to add the remote to. This change returns an explicit error when these flags are combined, providing clear feedback instead of silently ignoring the --remote flag. Fixes #2722 Signed-off-by: majiayu000 <1835304752@qq.com>
This commit is contained in:
parent
6acf74e04e
commit
3f0044fd94
2 changed files with 10 additions and 0 deletions
|
|
@ -113,6 +113,10 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
|
|||
opts.Rename = true // Any existing 'origin' will be renamed to upstream
|
||||
}
|
||||
|
||||
if opts.Repository != "" && cmd.Flags().Changed("remote") {
|
||||
return cmdutil.FlagErrorf("the `--remote` flag is unsupported when a repository argument is provided")
|
||||
}
|
||||
|
||||
if promptOk {
|
||||
// We can prompt for these if they were not specified.
|
||||
opts.PromptClone = !cmd.Flags().Changed("clone")
|
||||
|
|
|
|||
|
|
@ -144,6 +144,12 @@ func TestNewCmdFork(t *testing.T) {
|
|||
Rename: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "remote with repo argument",
|
||||
cli: "foo/bar --remote",
|
||||
wantErr: true,
|
||||
errMsg: "the `--remote` flag is unsupported when a repository argument is provided",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue