| 31 | } |
| 32 | |
| 33 | func NewCmdClone(f *cmdutil.Factory, runF func(*CloneOptions) error) *cobra.Command { |
| 34 | opts := &CloneOptions{ |
| 35 | IO: f.IOStreams, |
| 36 | HttpClient: f.HttpClient, |
| 37 | GitClient: f.GitClient, |
| 38 | Config: f.Config, |
| 39 | } |
| 40 | |
| 41 | cmd := &cobra.Command{ |
| 42 | DisableFlagsInUseLine: true, |
| 43 | |
| 44 | Use: "clone <repository> [<directory>] [-- <gitflags>...]", |
| 45 | Args: cmdutil.MinimumArgs(1, "cannot clone: repository argument required"), |
| 46 | Short: "Clone a repository locally", |
| 47 | Long: heredoc.Docf(` |
| 48 | Clone a GitHub repository locally. Pass additional %[1]sgit clone%[1]s flags by listing |
| 49 | them after %[1]s--%[1]s. |
| 50 | |
| 51 | If the %[1]sOWNER/%[1]s portion of the %[1]sOWNER/REPO%[1]s repository argument is omitted, it |
| 52 | defaults to the name of the authenticating user. |
| 53 | |
| 54 | When a protocol scheme is not provided in the repository argument, the %[1]sgit_protocol%[1]s will be |
| 55 | chosen from your configuration, which can be checked via %[1]sgh config get git_protocol%[1]s. If the protocol |
| 56 | scheme is provided, the repository will be cloned using the specified protocol. |
| 57 | |
| 58 | If the repository is a fork, its parent repository will be added as an additional |
| 59 | git remote called %[1]supstream%[1]s. The remote name can be configured using %[1]s--upstream-remote-name%[1]s. |
| 60 | The %[1]s--upstream-remote-name%[1]s option supports an %[1]s@owner%[1]s value which will name |
| 61 | the remote after the owner of the parent repository. |
| 62 | |
| 63 | If the repository is a fork, its parent repository will be set as the default remote repository. |
| 64 | To skip this behavior, use %[1]s--no-upstream%[1]s. |
| 65 | `, "`"), |
| 66 | Example: heredoc.Doc(` |
| 67 | # Clone a repository from a specific org |
| 68 | $ gh repo clone cli/cli |
| 69 | |
| 70 | # Clone a repository from your own account |
| 71 | $ gh repo clone myrepo |
| 72 | |
| 73 | # Clone a repo, overriding git protocol configuration |
| 74 | $ gh repo clone https://github.com/cli/cli |
| 75 | $ gh repo clone git@github.com:cli/cli.git |
| 76 | |
| 77 | # Clone a repository to a custom directory |
| 78 | $ gh repo clone cli/cli workspace/cli |
| 79 | |
| 80 | # Clone a repository with additional git clone flags |
| 81 | $ gh repo clone cli/cli -- --depth=1 |
| 82 | |
| 83 | # Clone a fork without adding an upstream remote |
| 84 | $ gh repo clone myfork --no-upstream |
| 85 | `), |
| 86 | RunE: func(cmd *cobra.Command, args []string) error { |
| 87 | opts.Repository = args[0] |
| 88 | opts.GitArgs = args[1:] |
| 89 | |
| 90 | if runF != nil { |