@@ -5,15 +5,25 @@ package lazycommit
55import "github.com/go-git/go-git/v5"
66
77// LazyRepo is a wrapper around go-git's Repository for simpler usage.
8- type LazyRepo git.Repository
8+ type LazyRepo struct {
9+ * git.Repository
10+ wt * git.Worktree
11+ }
912
1013// OpenRepo opens a repository at the given path.
1114func OpenRepo (path string ) (* LazyRepo , error ) {
1215 repo , err := git .PlainOpen (path )
1316 if err != nil {
1417 return nil , err
1518 }
16- return (* LazyRepo )(repo ), nil
19+ wt , err := repo .Worktree ()
20+ if err != nil {
21+ return nil , err
22+ }
23+ return & LazyRepo {
24+ Repository : repo ,
25+ wt : wt ,
26+ }, nil
1727}
1828
1929// NoStaged checks if there are no staged changes (added files, changed files, removed files)
@@ -35,23 +45,10 @@ func (r *LazyRepo) NoStaged() (bool, error) {
3545
3646// StageAll stages all changes in the repository.
3747func (r * LazyRepo ) StageAll () error {
38- wt , err := (* git .Repository )(r ).Worktree ()
39- if err != nil {
40- return err
41- }
42- return wt .AddWithOptions (& git.AddOptions {All : true })
43- }
44-
45- // Worktree gets the repo's worktree.
46- func (r * LazyRepo ) worktree () (* git.Worktree , error ) {
47- return (* git .Repository )(r ).Worktree ()
48+ return r .wt .AddWithOptions (& git.AddOptions {All : true })
4849}
4950
5051// Status gets the repo's status.
5152func (r * LazyRepo ) status () (git.Status , error ) {
52- wt , err := r .worktree ()
53- if err != nil {
54- return nil , err
55- }
56- return wt .Status ()
53+ return r .wt .Status ()
5754}
0 commit comments