@@ -18,6 +18,7 @@ import (
1818 "github.com/cli/cli/pkg/prompt"
1919 "github.com/cli/cli/utils"
2020 "github.com/spf13/cobra"
21+ "github.com/spf13/pflag"
2122)
2223
2324type ForkOptions struct {
@@ -27,6 +28,7 @@ type ForkOptions struct {
2728 BaseRepo func () (ghrepo.Interface , error )
2829 Remotes func () (context.Remotes , error )
2930
31+ GitArgs []string
3032 Repository string
3133 Clone bool
3234 Remote bool
@@ -48,16 +50,19 @@ func NewCmdFork(f *cmdutil.Factory, runF func(*ForkOptions) error) *cobra.Comman
4850 }
4951
5052 cmd := & cobra.Command {
51- Use : "fork [<repository>]" ,
52- Args : cobra .MaximumNArgs (1 ),
53+ Use : "fork [<repository>] [-- <gitflags>...] " ,
54+ Args : cobra .MaximumNArgs (2 ),
5355 Short : "Create a fork of a repository" ,
5456 Long : `Create a fork of a repository.
5557
56- With no argument, creates a fork of the current repository. Otherwise, forks the specified repository.` ,
58+ With no argument, creates a fork of the current repository. Otherwise, forks the specified repository.
59+
60+ If '--clone' is specified, you can pass aditional 'git clone' flags by listing them after '--'.` ,
5761 RunE : func (cmd * cobra.Command , args []string ) error {
5862 promptOk := opts .IO .CanPrompt ()
5963 if len (args ) > 0 {
6064 opts .Repository = args [0 ]
65+ opts .GitArgs = args [1 :]
6166 }
6267
6368 if promptOk && ! cmd .Flags ().Changed ("clone" ) {
@@ -74,6 +79,12 @@ With no argument, creates a fork of the current repository. Otherwise, forks the
7479 return forkRun (opts )
7580 },
7681 }
82+ cmd .SetFlagErrorFunc (func (cmd * cobra.Command , err error ) error {
83+ if err == pflag .ErrHelp {
84+ return err
85+ }
86+ return & cmdutil.FlagError {Err : fmt .Errorf ("%w\n Separate git clone flags with '--'." , err )}
87+ })
7788
7889 cmd .Flags ().BoolVar (& opts .Clone , "clone" , false , "Clone the fork {true|false}" )
7990 cmd .Flags ().BoolVar (& opts .Remote , "remote" , false , "Add remote for fork {true|false}" )
@@ -248,7 +259,7 @@ func forkRun(opts *ForkOptions) error {
248259 }
249260 if cloneDesired {
250261 forkedRepoURL := ghrepo .FormatRemoteURL (forkedRepo , protocol )
251- cloneDir , err := git .RunClone (forkedRepoURL , [] string {} )
262+ cloneDir , err := git .RunClone (forkedRepoURL , opts . GitArgs )
252263 if err != nil {
253264 return fmt .Errorf ("failed to clone fork: %w" , err )
254265 }
0 commit comments