MCPcopy Create free account
hub / github.com/belak/gitdir / Open

Function Open

internal/git/repository.go:34–64  ·  view source on GitHub ↗

Open will open a repository if it exists.

(baseFS billy.Filesystem, path string)

Source from the content-addressed store, hash-verified

32
33// Open will open a repository if it exists.
34func Open(baseFS billy.Filesystem, path string) (*Repository, error) {
35 // This lets us sanitize the path and ensure it always has .git on the end.
36 path = strings.TrimSuffix(path, ".git") + ".git"
37
38 fs, err := baseFS.Chroot(path)
39 if err != nil {
40 return nil, err
41 }
42
43 repoFS := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
44
45 // TODO: this probably shouldn't be memfs.
46 worktreeFS := memfs.New()
47
48 repo, err := git.Open(repoFS, worktreeFS)
49 if err != nil {
50 return nil, err
51 }
52
53 worktree, err := repo.Worktree()
54 if err != nil {
55 return nil, err
56 }
57
58 return &Repository{
59 Repo: repo,
60 RepoFS: repoFS,
61 Worktree: worktree,
62 WorktreeFS: worktreeFS,
63 }, nil
64}
65
66// EnsureRepo will open a repository if it exists and try to create it if it
67// doesn't.

Callers 1

EnsureRepoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected