about summary refs log tree commit diff stats
path: root/internal/vcs/repository.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/vcs/repository.go')
-rw-r--r--internal/vcs/repository.go26
1 files changed, 21 insertions, 5 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go
index 625fbd2..66c8c74 100644
--- a/internal/vcs/repository.go
+++ b/internal/vcs/repository.go
@@ -6,6 +6,7 @@ import (
 	"website/internal/log"
 
 	"github.com/go-git/go-git/v5"
+	"github.com/go-git/go-git/v5/plumbing/object"
 	"github.com/pkg/errors"
 )
 
@@ -28,14 +29,12 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 		if !errors.Is(err, git.ErrRepositoryAlreadyExists) {
 			return nil, err
 		}
-		gr, err = git.PlainOpen(cfg.LocalPath)
+		repo, err := Open(cfg.LocalPath)
 		if err != nil {
 			return nil, err
 		}
-		repo := &Repository{
-			repo: gr,
-		}
-		_, err := repo.Update(cfg)
+
+		_, err = repo.Update(cfg)
 		if err != nil {
 			return nil, err
 		}
@@ -48,6 +47,16 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 	}, nil
 }
 
+func Open(path string) (*Repository, error) {
+	gr, err := git.PlainOpen(path)
+	if err != nil {
+		return nil, err
+	}
+	return &Repository{
+		repo: gr,
+	}, nil
+}
+
 func (r *Repository) Update(cfg *Config) (bool, error) {
 	log.Info("updating repository")
 
@@ -101,3 +110,10 @@ func (r *Repository) Clean(wt *git.Worktree) error {
 
 	return nil
 }
+
+func (r *Repository) FileLog(filename string) (object.CommitIter, error) {
+	return r.repo.Log(&git.LogOptions{
+		Order:    git.LogOrderCommitterTime,
+		FileName: &filename,
+	})
+}