about summary refs log tree commit diff stats
path: root/internal/vcs
diff options
context:
space:
mode:
authorAlan Pearce2024-06-28 20:43:14 +0200
committerAlan Pearce2024-06-29 16:50:51 +0200
commit6c4a3268bc4c528ecff45f50ed5ca6aa1d48500c (patch)
tree6663946e586d5c0745b984a0a809fc2330ce70d0 /internal/vcs
parentb4095d108a2646bcf9e7fff64788b10d9bce8da3 (diff)
downloadwebsite-6c4a3268bc4c528ecff45f50ed5ca6aa1d48500c.tar.lz
website-6c4a3268bc4c528ecff45f50ed5ca6aa1d48500c.tar.zst
website-6c4a3268bc4c528ecff45f50ed5ca6aa1d48500c.zip
Diffstat (limited to 'internal/vcs')
-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,
+	})
+}