X Tutup
Skip to content

Commit 99c312e

Browse files
author
vilmibm
committed
accept a remote name instead of doing magic remote naming in repo fork
1 parent 03f99a0 commit 99c312e

File tree

1 file changed

+4
-31
lines changed

1 file changed

+4
-31
lines changed

pkg/cmd/repo/fork/fork.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ import (
77
"strings"
88
"time"
99

10-
"github.com/AlecAivazis/survey/v2"
1110
"github.com/cli/cli/api"
1211
"github.com/cli/cli/context"
1312
"github.com/cli/cli/git"
1413
"github.com/cli/cli/internal/config"
1514
"github.com/cli/cli/internal/ghrepo"
16-
"github.com/cli/cli/internal/run"
1715
"github.com/cli/cli/pkg/cmdutil"
1816
"github.com/cli/cli/pkg/iostreams"
1917
"github.com/cli/cli/pkg/prompt"
@@ -33,6 +31,7 @@ type ForkOptions struct {
3331
Remote bool
3432
PromptClone bool
3533
PromptRemote bool
34+
RemoteName string
3635
}
3736

3837
var Since = func(t time.Time) time.Duration {
@@ -78,6 +77,7 @@ With no argument, creates a fork of the current repository. Otherwise, forks the
7877

7978
cmd.Flags().BoolVar(&opts.Clone, "clone", false, "Clone the fork {true|false}")
8079
cmd.Flags().BoolVar(&opts.Remote, "remote", false, "Add remote for fork {true|false}")
80+
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", "origin", "Specify a name for a fork's new remote.")
8181

8282
return cmd
8383
}
@@ -226,40 +226,13 @@ func forkRun(opts *ForkOptions) error {
226226
}
227227
}
228228
if remoteDesired {
229-
remoteName := ""
230-
err = prompt.SurveyAskOne(&survey.Input{
231-
Message: "Fork remote name?",
232-
Default: "origin",
233-
}, &remoteName)
234-
if err != nil {
235-
return fmt.Errorf("failed to prompt: %w", err)
236-
}
237-
229+
remoteName := opts.RemoteName
238230
remotes, err := opts.Remotes()
239231
if err != nil {
240232
return err
241233
}
242234
if _, err := remotes.FindByName(remoteName); err == nil {
243-
renameTarget := ""
244-
err = prompt.SurveyAskOne(&survey.Input{
245-
Message: "There is already remote with same name. Source remote name?",
246-
Default: "upstream",
247-
}, &renameTarget)
248-
if err != nil {
249-
return fmt.Errorf("failed to prompt: %w", err)
250-
}
251-
252-
renameCmd, err := git.GitCommand("remote", "rename", remoteName, renameTarget)
253-
if err != nil {
254-
return err
255-
}
256-
err = run.PrepareCmd(renameCmd).Run()
257-
if err != nil {
258-
return err
259-
}
260-
if connectedToTerminal {
261-
fmt.Fprintf(stderr, "%s Renamed %s remote to %s\n", cs.SuccessIcon(), cs.Bold(remoteName), cs.Bold(renameTarget))
262-
}
235+
return fmt.Errorf("a remote called '%s' already exists. You can rerun this command with --remote-name to specify a different remote name.", remoteName)
263236
}
264237

265238
forkedRepoCloneURL := ghrepo.FormatRemoteURL(forkedRepo, protocol)

0 commit comments

Comments
 (0)
X Tutup