all repos — website @ 59a3323f6eec9d0b38d2c10ccf514f83ca12b419

My website

use remote-tracking branch for merge
Alan Pearce alan@alanpearce.eu
Tue, 25 Jun 2024 21:14:42 +0200
commit

59a3323f6eec9d0b38d2c10ccf514f83ca12b419

parent

b87f220fe3e0bd8f77c31ed1677f2df337c6ce8d

1 files changed, 7 insertions(+), 10 deletions(-)

jump to
M internal/vcs/repository.gointernal/vcs/repository.go
@@ -7,6 +7,7 @@ "website/internal/log" 
 	"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 @@ }, nil }
 
 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 @@ "+refs/heads/" + cfg.Branch + ":refs/remotes/origin/" + cfg.Branch, 			),
 		},
 	})
-	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,
 	})