MCPcopy
hub / github.com/go-git/go-git / clone

Method clone

repository.go:892–1008  ·  view source on GitHub ↗

Clone clones a remote repository

(ctx context.Context, o *CloneOptions)

Source from the content-addressed store, hash-verified

890
891// Clone clones a remote repository
892func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
893 if err := o.Validate(); err != nil {
894 return err
895 }
896
897 c := &config.RemoteConfig{
898 Name: o.RemoteName,
899 URLs: []string{o.URL},
900 Fetch: r.cloneRefSpec(o),
901 Mirror: o.Mirror,
902 }
903
904 if _, err := r.CreateRemote(c); err != nil {
905 return err
906 }
907
908 // When the repository to clone is on the local machine,
909 // instead of using hard links, automatically setup .git/objects/info/alternates
910 // to share the objects with the source repository
911 if o.Shared {
912 if !url.IsLocalEndpoint(o.URL) {
913 return ErrAlternatePathNotSupported
914 }
915 altpath := o.URL
916 remoteRepo, err := PlainOpen(o.URL)
917 if err != nil {
918 return fmt.Errorf("failed to open remote repository: %w", err)
919 }
920 conf, err := remoteRepo.Config()
921 if err != nil {
922 return fmt.Errorf("failed to read remote repository configuration: %w", err)
923 }
924 if !conf.Core.IsBare {
925 altpath = path.Join(altpath, GitDirName)
926 }
927 if err := r.Storer.AddAlternate(altpath); err != nil {
928 return fmt.Errorf("failed to add alternate file to git objects dir: %w", err)
929 }
930 }
931
932 ref, err := r.fetchAndUpdateReferences(ctx, &FetchOptions{
933 RefSpecs: c.Fetch,
934 Depth: o.Depth,
935 Auth: o.Auth,
936 Progress: o.Progress,
937 Tags: o.Tags,
938 RemoteName: o.RemoteName,
939 InsecureSkipTLS: o.InsecureSkipTLS,
940 ClientCert: o.ClientCert,
941 ClientKey: o.ClientKey,
942 CABundle: o.CABundle,
943 ProxyOptions: o.ProxyOptions,
944 }, o.ReferenceName)
945 if err != nil {
946 return err
947 }
948
949 if r.wt != nil && !o.NoCheckout {

Calls 15

cloneRefSpecMethod · 0.95
CreateRemoteMethod · 0.95
WorktreeMethod · 0.95
HeadMethod · 0.95
CreateBranchMethod · 0.95
IsLocalEndpointFunction · 0.92
PlainOpenFunction · 0.85
JoinMethod · 0.80
updateSubmodulesMethod · 0.80
IsBranchMethod · 0.80

Tested by 15

TestCloneDeepMethod · 0.64
TestCloneConfigMethod · 0.64
TestCloneSingleBranchMethod · 0.64
TestCloneSingleTagMethod · 0.64
TestCloneDetachedHEADMethod · 0.64
TestLogMethod · 0.64
TestLogAllMethod · 0.64