MCPcopy Create free account
hub / github.com/cli/cli / Clone

Method Clone

git/client.go:923–957  ·  view source on GitHub ↗
(ctx context.Context, cloneURL string, args []string, mods ...CommandModifier)

Source from the content-addressed store, hash-verified

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

Callers 1

TestClientCloneFunction · 0.95

Calls 6

AuthenticatedCommandMethod · 0.95
parseCloneArgsFunction · 0.85
BaseMethod · 0.80
ContainsMethod · 0.80
RunMethod · 0.65

Tested by 1

TestClientCloneFunction · 0.76