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