Skip to content

Commit b515699

Browse files
committed
repo fork: honor --remote with repo arg
1 parent 4e65637 commit b515699

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pkg/cmd/repo/fork/fork.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ func forkRun(opts *ForkOptions) error {
182182
return fmt.Errorf("argument error: %w", err)
183183
}
184184
}
185+
186+
if opts.Remote {
187+
if remotes, err := opts.Remotes(); err == nil {
188+
if _, err := remotes.FindByRepo(repoToFork.RepoOwner(), repoToFork.RepoName()); err == nil {
189+
inParent = true
190+
}
191+
}
192+
}
185193
}
186194

187195
connectedToTerminal := opts.IO.IsStdoutTTY() && opts.IO.IsStderrTTY() && opts.IO.IsStdinTTY()

pkg/cmd/repo/fork/fork_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,22 @@ func TestRepoFork(t *testing.T) {
372372
},
373373
wantErrOut: "✓ Created fork someone/REPO\n✓ Renamed remote origin to upstream\n✓ Added remote origin\n",
374374
},
375+
{
376+
name: "repo arg matches remote --remote",
377+
tty: true,
378+
opts: &ForkOptions{
379+
Repository: "https://github.com/OWNER/REPO.git",
380+
Remote: true,
381+
RemoteName: defaultRemoteName,
382+
Rename: true,
383+
},
384+
httpStubs: forkPost,
385+
execStubs: func(cs *run.CommandStubber) {
386+
cs.Register("git remote rename origin upstream", 0, "")
387+
cs.Register(`git remote add origin https://github.com/someone/REPO.git`, 0, "")
388+
},
389+
wantErrOut: "✓ Created fork someone/REPO\n✓ Renamed remote origin to upstream\n✓ Added remote origin\n",
390+
},
375391
{
376392
name: "implicit nontty reuse existing remote",
377393
opts: &ForkOptions{

0 commit comments

Comments
 (0)