MCPcopy
hub / github.com/cli/cli / Clone

Method Clone

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

Source from the content-addressed store, hash-verified

858}
859
860func (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
896func resolveGitPath() (string, error) {
897 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