Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
repo fork: honor --remote with repo arg
  • Loading branch information
VedantMadane committed Feb 10, 2026
commit b51569987116f96f65d7edbb467c37a3de873f05
8 changes: 8 additions & 0 deletions pkg/cmd/repo/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ func forkRun(opts *ForkOptions) error {
return fmt.Errorf("argument error: %w", err)
}
}

if opts.Remote {
if remotes, err := opts.Remotes(); err == nil {
if _, err := remotes.FindByRepo(repoToFork.RepoOwner(), repoToFork.RepoName()); err == nil {
inParent = true
}
}
}
}

connectedToTerminal := opts.IO.IsStdoutTTY() && opts.IO.IsStderrTTY() && opts.IO.IsStdinTTY()
Expand Down
16 changes: 16 additions & 0 deletions pkg/cmd/repo/fork/fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,22 @@ func TestRepoFork(t *testing.T) {
},
wantErrOut: "✓ Created fork someone/REPO\n✓ Renamed remote origin to upstream\n✓ Added remote origin\n",
},
{
name: "repo arg matches remote --remote",
tty: true,
opts: &ForkOptions{
Repository: "https://github.com/OWNER/REPO.git",
Remote: true,
RemoteName: defaultRemoteName,
Rename: true,
},
httpStubs: forkPost,
execStubs: func(cs *run.CommandStubber) {
cs.Register("git remote rename origin upstream", 0, "")
cs.Register(`git remote add origin https://github.com/someone/REPO.git`, 0, "")
},
wantErrOut: "✓ Created fork someone/REPO\n✓ Renamed remote origin to upstream\n✓ Added remote origin\n",
},
{
name: "implicit nontty reuse existing remote",
opts: &ForkOptions{
Expand Down