about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-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
 }