Skip to content

Commit 3f0044f

Browse files
committed
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 cli#2722 Signed-off-by: majiayu000 <1835304752@qq.com>
1 parent 6acf74e commit 3f0044f

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

pkg/cmd/repo/fork/fork.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
113113
opts.Rename = true // Any existing 'origin' will be renamed to upstream
114114
}
115115

116+
if opts.Repository != "" && cmd.Flags().Changed("remote") {
117+
return cmdutil.FlagErrorf("the `--remote` flag is unsupported when a repository argument is provided")
118+
}
119+
116120
if promptOk {
117121
// We can prompt for these if they were not specified.
118122
opts.PromptClone = !cmd.Flags().Changed("clone")

pkg/cmd/repo/fork/fork_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ func TestNewCmdFork(t *testing.T) {
144144
Rename: false,
145145
},
146146
},
147+
{
148+
name: "remote with repo argument",
149+
cli: "foo/bar --remote",
150+
wantErr: true,
151+
errMsg: "the `--remote` flag is unsupported when a repository argument is provided",
152+
},
147153
}
148154

149155
for _, tt := range tests {

0 commit comments

Comments
 (0)