@@ -29,8 +29,13 @@ var repoCmd = &cobra.Command{
2929// gitCloneArgs builds the argv for git clone. The -- separator stops git
3030// from parsing a server-supplied CloneURL as an option (a malicious forge
3131// could otherwise return something like --upload-pack=...).
32- func gitCloneArgs (url string ) []string {
33- return []string {"clone" , "--" , url }
32+ func gitCloneArgs (url string , dest string , gitFlags []string ) []string {
33+ args := append ([]string {"clone" }, gitFlags ... )
34+ args = append (args , "--" , url )
35+ if dest != "" {
36+ args = append (args , dest )
37+ }
38+ return args
3439}
3540
3641func init () {
@@ -274,7 +279,7 @@ func repoCreateCmd() *cobra.Command {
274279 _ , _ = fmt .Fprintf (os .Stdout , "%s\n " , repo .HTMLURL )
275280
276281 if flagClone && repo .CloneURL != "" {
277- cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (repo .CloneURL )... )
282+ cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (repo .CloneURL , "" , nil )... )
278283 cloneCmd .Stdout = os .Stdout
279284 cloneCmd .Stderr = os .Stderr
280285 return cloneCmd .Run ()
@@ -442,7 +447,7 @@ func repoForkCmd() *cobra.Command {
442447 _ , _ = fmt .Fprintf (os .Stdout , "%s\n " , r .HTMLURL )
443448
444449 if flagClone && r .CloneURL != "" {
445- cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (r .CloneURL )... )
450+ cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (r .CloneURL , "" , nil )... )
446451 cloneCmd .Stdout = os .Stdout
447452 cloneCmd .Stderr = os .Stderr
448453 return cloneCmd .Run ()
@@ -460,11 +465,32 @@ func repoForkCmd() *cobra.Command {
460465
461466func repoCloneCmd () * cobra.Command {
462467 return & cobra.Command {
463- Use : "clone <OWNER/REPO>" ,
468+ Use : "clone <OWNER/REPO> [PATH] [-- <gitflags>...] " ,
464469 Short : "Clone a repository locally" ,
465- Args : cobra .ExactArgs (1 ),
466470 RunE : func (cmd * cobra.Command , args []string ) error {
467- forge , owner , repoName , _ , err := resolve .Repo (args [0 ], flagForgeType )
471+ dashIdx := cmd .ArgsLenAtDash ()
472+ positional := len (args )
473+ if dashIdx != - 1 {
474+ positional = dashIdx
475+ }
476+ if positional < 1 {
477+ return fmt .Errorf ("repository argument required" )
478+ }
479+ if positional > 2 {
480+ return fmt .Errorf ("accepts at most 2 arg(s) before --, received %d" , positional )
481+ }
482+
483+ repoArg := args [0 ]
484+ var dest string
485+ if positional > 1 {
486+ dest = args [1 ]
487+ }
488+ var gitFlags []string
489+ if dashIdx != - 1 {
490+ gitFlags = args [dashIdx :]
491+ }
492+
493+ forge , owner , repoName , _ , err := resolve .Repo (repoArg , flagForgeType )
468494 if err != nil {
469495 return err
470496 }
@@ -479,7 +505,7 @@ func repoCloneCmd() *cobra.Command {
479505 cloneURL = r .HTMLURL + ".git"
480506 }
481507
482- cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (cloneURL )... )
508+ cloneCmd := exec .CommandContext (cmd .Context (), "git" , gitCloneArgs (cloneURL , dest , gitFlags )... )
483509 cloneCmd .Stdout = os .Stdout
484510 cloneCmd .Stderr = os .Stderr
485511 return cloneCmd .Run ()
0 commit comments