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

Method Clone

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

Source from the content-addressed store, hash-verified

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

Calls 6

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