From 59a3323f6eec9d0b38d2c10ccf514f83ca12b419 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 25 Jun 2024 21:14:42 +0200 Subject: use remote-tracking branch for merge --- internal/vcs/repository.go | 17 +++++++---------- 1 file 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, }) -- cgit 1.4.1