about summary refs log tree commit diff stats
path: root/internal/vcs/repository.go
diff options
context:
space:
mode:
authorAlan Pearce2024-06-25 21:14:42 +0200
committerAlan Pearce2024-06-25 21:14:42 +0200
commit59a3323f6eec9d0b38d2c10ccf514f83ca12b419 (patch)
tree0120506f3fead675f7aa5ba534ee13289b2f8991 /internal/vcs/repository.go
parentb87f220fe3e0bd8f77c31ed1677f2df337c6ce8d (diff)
downloadwebsite-59a3323f6eec9d0b38d2c10ccf514f83ca12b419.tar.lz
website-59a3323f6eec9d0b38d2c10ccf514f83ca12b419.tar.zst
website-59a3323f6eec9d0b38d2c10ccf514f83ca12b419.zip
use remote-tracking branch for merge
Diffstat (limited to 'internal/vcs/repository.go')
-rw-r--r--internal/vcs/repository.go17
1 files changed, 7 insertions, 10 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go
index 56d439d..6e8f079 100644
--- a/internal/vcs/repository.go
+++ b/internal/vcs/repository.go
@@ -7,6 +7,7 @@ import (
 
 	"github.com/go-git/go-git/v5"
 	gitc "github.com/go-git/go-git/v5/config"
+	"github.com/go-git/go-git/v5/plumbing"
 	"github.com/pkg/errors"
 )
 
@@ -50,7 +51,7 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 }
 
 func (r *Repository) Update(cfg *Config) (bool, error) {
-	log.Debug("updating repository")
+	log.Info("updating repository")
 	err := r.repo.Fetch(&git.FetchOptions{
 		RefSpecs: []gitc.RefSpec{
 			gitc.RefSpec(
@@ -58,21 +59,17 @@ 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
-		}
-
+	if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
 		return false, err
 	}
 
-	head, err := r.repo.Head()
+	ref, err := r.repo.Reference(plumbing.ReferenceName("refs/remotes/origin/"+cfg.Branch), true)
 	if err != nil {
 		return false, err
 	}
-	log.Debug("applying changes", "head", head.Name())
-	err = r.repo.Merge(*head, git.MergeOptions{
+
+	log.Info("applying changes", "hash", ref.Hash().String())
+	err = r.repo.Merge(*ref, git.MergeOptions{
 		Strategy: git.FastForwardMerge,
 	})