| 858 | } |
| 859 | |
| 860 | func (c *Client) Clone(ctx context.Context, cloneURL string, args []string, mods ...CommandModifier) (string, error) { |
| 861 | // Note that even if this is an SSH clone URL, we are setting the pattern anyway. |
| 862 | // We could write some code to prevent this, but it also doesn't seem harmful. |
| 863 | pattern, err := CredentialPatternFromGitURL(cloneURL) |
| 864 | if err != nil { |
| 865 | return "", err |
| 866 | } |
| 867 | |
| 868 | cloneArgs, target := parseCloneArgs(args) |
| 869 | cloneArgs = append(cloneArgs, cloneURL) |
| 870 | // If the args contain an explicit target, pass it to clone otherwise, |
| 871 | // parse the URL to determine where git cloned it to so we can return it. |
| 872 | if target != "" { |
| 873 | cloneArgs = append(cloneArgs, target) |
| 874 | } else { |
| 875 | target = path.Base(strings.TrimSuffix(cloneURL, ".git")) |
| 876 | |
| 877 | if slices.Contains(cloneArgs, "--bare") { |
| 878 | target += ".git" |
| 879 | } |
| 880 | } |
| 881 | cloneArgs = append([]string{"clone"}, cloneArgs...) |
| 882 | cmd, err := c.AuthenticatedCommand(ctx, pattern, cloneArgs...) |
| 883 | if err != nil { |
| 884 | return "", err |
| 885 | } |
| 886 | for _, mod := range mods { |
| 887 | mod(cmd) |
| 888 | } |
| 889 | err = cmd.Run() |
| 890 | if err != nil { |
| 891 | return "", err |
| 892 | } |
| 893 | return target, nil |
| 894 | } |
| 895 | |
| 896 | func resolveGitPath() (string, error) { |
| 897 | path, err := safeexec.LookPath("git") |