Open opens an existing local repository at the given path.
(rootPath, address string)
| 25 | |
| 26 | // Open opens an existing local repository at the given path. |
| 27 | func 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. |
| 53 | func Clone(ctx context.Context, rootPath, address string, shallow bool) (*Repository, error) { |