-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository.go
53 lines (42 loc) · 1023 Bytes
/
repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package git
import (
"io/fs"
"path/filepath"
"github.com/alevinval/vendor-go/internal/lock"
"github.com/alevinval/vendor-go/pkg/vending"
)
type Repository struct {
dep *vending.Dependency
git *Git
lock *lock.Lock
path string
}
func NewRepository(path string, lock *lock.Lock, dep *vending.Dependency) *Repository {
return &Repository{
dep: dep,
git: &Git{},
lock: lock,
path: path,
}
}
func (r *Repository) Path() string {
return r.path
}
func (r *Repository) OpenOrClone() error {
return r.git.OpenOrClone(r.dep.URL, r.dep.Branch, r.Path())
}
func (r *Repository) Fetch() error {
return r.git.Fetch(r.Path())
}
func (r *Repository) Reset(refname string) error {
return r.git.Reset(r.Path(), refname)
}
func (r *Repository) GetCurrentCommit() (string, error) {
return r.git.GetCurrentCommit(r.Path())
}
func (r *Repository) WalkDir(fn fs.WalkDirFunc) error {
return filepath.WalkDir(r.Path(), fn)
}
func (r *Repository) Lock() (*lock.Lock, error) {
return r.lock, r.lock.Acquire()
}