about summary refs log tree commit diff stats
path: root/internal/vcs
diff options
context:
space:
mode:
authorAlan Pearce2024-06-25 20:50:53 +0200
committerAlan Pearce2024-06-25 20:50:53 +0200
commitb87f220fe3e0bd8f77c31ed1677f2df337c6ce8d (patch)
tree3775cc5fde036bb31eb0751a59aed719395fd53d /internal/vcs
parent7550950f27e5904cfb23ca492feb402edafbcb9a (diff)
downloadwebsite-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.tar.lz
website-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.tar.zst
website-b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d.zip
update worktree after fetching updates
Diffstat (limited to 'internal/vcs')
-rw-r--r--internal/vcs/repository.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go
index cc9bdaa..56d439d 100644
--- a/internal/vcs/repository.go
+++ b/internal/vcs/repository.go
@@ -3,6 +3,7 @@ package vcs
 import (
 	"os"
 	"website/internal/config"
+	"website/internal/log"
 
 	"github.com/go-git/go-git/v5"
 	gitc "github.com/go-git/go-git/v5/config"
@@ -39,6 +40,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 		if err != nil {
 			return nil, err
 		}
+
 		return repo, nil
 	}
 
@@ -48,6 +50,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 }
 
 func (r *Repository) Update(cfg *Config) (bool, error) {
+	log.Debug("updating repository")
 	err := r.repo.Fetch(&git.FetchOptions{
 		RefSpecs: []gitc.RefSpec{
 			gitc.RefSpec(
@@ -57,9 +60,21 @@ func (r *Repository) Update(cfg *Config) (bool, error) {
 	})
 	if err != nil {
 		if errors.Is(err, git.NoErrAlreadyUpToDate) {
+			log.Debug("no changes to pull")
 			return false, nil
 		}
+
+		return false, err
+	}
+
+	head, err := r.repo.Head()
+	if err != nil {
 		return false, err
 	}
+	log.Debug("applying changes", "head", head.Name())
+	err = r.repo.Merge(*head, git.MergeOptions{
+		Strategy: git.FastForwardMerge,
+	})
+
 	return true, nil
 }