| 920 | } |
| 921 | |
| 922 | func (c *Client) Clone(ctx context.Context, cloneURL string, args []string, mods ...CommandModifier) (string, error) { |
| 923 | // Note that even if this is an SSH clone URL, we are setting the pattern anyway. |
| 924 | // We could write some code to prevent this, but it also doesn't seem harmful. |
| 925 | pattern, err := CredentialPatternFromGitURL(cloneURL) |
| 926 | if err != nil { |
| 927 | return "", err |
| 928 | } |
| 929 | |
| 930 | cloneArgs, target := parseCloneArgs(args) |
| 931 | cloneArgs = append(cloneArgs, cloneURL) |
| 932 | // If the args contain an explicit target, pass it to clone otherwise, |
| 933 | // parse the URL to determine where git cloned it to so we can return it. |
| 934 | if target != "" { |
| 935 | cloneArgs = append(cloneArgs, target) |
| 936 | } else { |
| 937 | target = path.Base(strings.TrimSuffix(cloneURL, ".git")) |
| 938 | |
| 939 | if slices.Contains(cloneArgs, "--bare") { |
| 940 | target += ".git" |
| 941 | } |
| 942 | } |
| 943 | cloneArgs = append([]string{"clone"}, cloneArgs...) |
| 944 | cmd, err := c.AuthenticatedCommand(ctx, pattern, cloneArgs...) |
| 945 | if err != nil { |
| 946 | return "", err |
| 947 | } |
| 948 | for _, mod := range mods { |
| 949 | mod(cmd) |
| 950 | } |
| 951 | err = cmd.Run() |
| 952 | if err != nil { |
| 953 | return "", err |
| 954 | } |
| 955 | return target, nil |
| 956 | } |
| 957 | |
| 958 | func resolveGitPath() (string, error) { |
| 959 | path, err := safeexec.LookPath("git") |