Skip to content

Commit

Permalink
repo fork: tweak docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Feb 18, 2022
1 parent 1eefda0 commit 512208c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions pkg/cmd/repo/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/cli/cli/v2/api"
"github.com/cli/cli/v2/context"
"github.com/cli/cli/v2/git"
Expand Down Expand Up @@ -61,21 +62,23 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
Use: "fork [<repository>] [-- <gitflags>...]",
Args: func(cmd *cobra.Command, args []string) error {
if cmd.ArgsLenAtDash() == 0 && len(args[1:]) > 0 {
return cmdutil.FlagErrorf("repository argument required when passing 'git clone' flags")
return cmdutil.FlagErrorf("repository argument required when passing git clone flags")
}
return nil
},
Short: "Create a fork of a repository",
Long: `Create a fork of a repository.
Long: heredoc.Docf(`
Create a fork of a repository.
With no argument, creates a fork of the current repository. Otherwise, forks
the specified repository.
With no argument, creates a fork of the current repository. Otherwise, forks
the specified repository.
By default, the new fork is set to be your 'origin' remote and any existing
origin remote is renamed to 'upstream'. To alter this behavior, you can set
a name for the new fork's remote with --remote-name.
By default, the new fork is set to be your "origin" remote and any existing
origin remote is renamed to "upstream". To alter this behavior, you can set
a name for the new fork's remote with %[1]s--remote-name%[1]s.
Additional 'git clone' flags can be passed in by listing them after '--'.`,
Additional git clone flags can be passed after %[1]s--%[1]s.
`, "`"),
RunE: func(cmd *cobra.Command, args []string) error {
promptOk := opts.IO.CanPrompt()
if len(args) > 0 {
Expand Down Expand Up @@ -109,14 +112,14 @@ Additional 'git clone' flags can be passed in by listing them after '--'.`,
if err == pflag.ErrHelp {
return err
}
return cmdutil.FlagErrorf("%w\nSeparate git clone flags with '--'.", err)
return cmdutil.FlagErrorf("%w\nSeparate git clone flags with `--`.", err)
})

cmd.Flags().BoolVar(&opts.Clone, "clone", false, "Clone the fork {true|false}")
cmd.Flags().BoolVar(&opts.Remote, "remote", false, "Add remote for fork {true|false}")
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", defaultRemoteName, "Specify a name for a fork's new remote.")
cmd.Flags().BoolVar(&opts.Clone, "clone", false, "Clone the fork")
cmd.Flags().BoolVar(&opts.Remote, "remote", false, "Add a git remote for the fork")
cmd.Flags().StringVar(&opts.RemoteName, "remote-name", defaultRemoteName, "Specify the name for the new remote")
cmd.Flags().StringVar(&opts.Organization, "org", "", "Create the fork in an organization")
cmd.Flags().StringVar(&opts.ForkName, "fork-name", "", "Specify a name for the forked repo")
cmd.Flags().StringVar(&opts.ForkName, "fork-name", "", "Rename the forked repository")

return cmd
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/repo/fork/fork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestNewCmdFork(t *testing.T) {
name: "git args without repo",
cli: "-- --foo bar",
wantErr: true,
errMsg: "repository argument required when passing 'git clone' flags",
errMsg: "repository argument required when passing git clone flags",
},
{
name: "repo",
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestNewCmdFork(t *testing.T) {
name: "git flags in wrong place",
cli: "--depth 1 OWNER/REPO",
wantErr: true,
errMsg: "unknown flag: --depth\nSeparate git clone flags with '--'.",
errMsg: "unknown flag: --depth\nSeparate git clone flags with `--`.",
},
{
name: "with fork name",
Expand Down

0 comments on commit 512208c

Please sign in to comment.