@@ -17,6 +17,7 @@ import (
1717 "github.com/cli/cli/pkg/prompt"
1818 "github.com/cli/cli/utils"
1919 "github.com/spf13/cobra"
20+ "github.com/spf13/pflag"
2021)
2122
2223type ForkOptions struct {
@@ -26,6 +27,7 @@ type ForkOptions struct {
2627 BaseRepo func () (ghrepo.Interface , error )
2728 Remotes func () (context.Remotes , error )
2829
30+ GitArgs []string
2931 Repository string
3032 Clone bool
3133 Remote bool
@@ -48,16 +50,24 @@ 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 : func (cmd * cobra.Command , args []string ) error {
55+ if cmd .ArgsLenAtDash () == 0 && len (args [1 :]) > 0 {
56+ return cmdutil.FlagError {Err : fmt .Errorf ("repository argument required when passing 'git clone' flags" )}
57+ }
58+ return nil
59+ },
5360 Short : "Create a fork of a repository" ,
5461 Long : `Create a fork of a repository.
5562
56- With no argument, creates a fork of the current repository. Otherwise, forks the specified repository.` ,
63+ With no argument, creates a fork of the current repository. Otherwise, forks the specified repository.
64+
65+ Additional 'git clone' flags can be passed in by listing them after '--'.` ,
5766 RunE : func (cmd * cobra.Command , args []string ) error {
5867 promptOk := opts .IO .CanPrompt ()
5968 if len (args ) > 0 {
6069 opts .Repository = args [0 ]
70+ opts .GitArgs = args [1 :]
6171 }
6272
6373 if promptOk && ! cmd .Flags ().Changed ("clone" ) {
@@ -74,6 +84,12 @@ With no argument, creates a fork of the current repository. Otherwise, forks the
7484 return forkRun (opts )
7585 },
7686 }
87+ cmd .SetFlagErrorFunc (func (cmd * cobra.Command , err error ) error {
88+ if err == pflag .ErrHelp {
89+ return err
90+ }
91+ return & cmdutil.FlagError {Err : fmt .Errorf ("%w\n Separate git clone flags with '--'." , err )}
92+ })
7793
7894 cmd .Flags ().BoolVar (& opts .Clone , "clone" , false , "Clone the fork {true|false}" )
7995 cmd .Flags ().BoolVar (& opts .Remote , "remote" , false , "Add remote for fork {true|false}" )
@@ -243,7 +259,7 @@ func forkRun(opts *ForkOptions) error {
243259 }
244260 if cloneDesired {
245261 forkedRepoURL := ghrepo .FormatRemoteURL (forkedRepo , protocol )
246- cloneDir , err := git .RunClone (forkedRepoURL , [] string {} )
262+ cloneDir , err := git .RunClone (forkedRepoURL , opts . GitArgs )
247263 if err != nil {
248264 return fmt .Errorf ("failed to clone fork: %w" , err )
249265 }
0 commit comments