MCPcopy
hub / github.com/zarf-dev/zarf / Open

Function Open

src/internal/git/repository.go:27–50  ·  view source on GitHub ↗

Open opens an existing local repository at the given path.

(rootPath, address string)

Source from the content-addressed store, hash-verified

25
26// Open opens an existing local repository at the given path.
27func Open(rootPath, address string) (*Repository, error) {
28 repoFolder, err := transform.GitURLtoFolderName(address)
29 if err != nil {
30 return nil, fmt.Errorf("unable to parse git url %s: %w", address, err)
31 }
32 repoPath := filepath.Join(rootPath, repoFolder)
33
34 // Check that this package is using the new repo format (if not fallback to the format from <= 0.24.x)
35 _, err = os.Stat(repoPath)
36 if err != nil && !os.IsNotExist(err) {
37 return nil, err
38 }
39 if os.IsNotExist(err) {
40 repoFolder, err = transform.GitURLtoRepoName(address)
41 if err != nil {
42 return nil, fmt.Errorf("unable to parse git url %s: %w", address, err)
43 }
44 repoPath = filepath.Join(rootPath, repoFolder)
45 }
46
47 return &Repository{
48 path: repoPath,
49 }, nil
50}
51
52// Clone clones a git repository to the given local path.
53func Clone(ctx context.Context, rootPath, address string, shallow bool) (*Repository, error) {

Callers 2

TestRepositoryFunction · 0.85

Calls 2

GitURLtoFolderNameFunction · 0.92
GitURLtoRepoNameFunction · 0.92

Tested by 1

TestRepositoryFunction · 0.68