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.go38
1 files changed, 23 insertions, 15 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go
index 6e8f079..8ee08b2 100644
--- a/internal/vcs/repository.go
+++ b/internal/vcs/repository.go
@@ -6,8 +6,6 @@ import (
 	"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"
 )
 
@@ -52,26 +50,36 @@ func CloneOrUpdate(cfg *Config) (*Repository, error) {
 
 func (r *Repository) Update(cfg *Config) (bool, error) {
 	log.Info("updating repository")
-	err := r.repo.Fetch(&git.FetchOptions{
-		RefSpecs: []gitc.RefSpec{
-			gitc.RefSpec(
-				"+refs/heads/" + cfg.Branch + ":refs/remotes/origin/" + cfg.Branch,
-			),
-		},
-	})
-	if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
+
+	head, err := r.repo.Head()
+	if err != nil {
 		return false, err
 	}
 
-	ref, err := r.repo.Reference(plumbing.ReferenceName("refs/remotes/origin/"+cfg.Branch), true)
+	log.Info("updating from", "rev", head.Hash().String())
+	wt, err := r.repo.Worktree()
 	if err != nil {
 		return false, err
 	}
-
-	log.Info("applying changes", "hash", ref.Hash().String())
-	err = r.repo.Merge(*ref, git.MergeOptions{
-		Strategy: git.FastForwardMerge,
+	err = wt.Pull(&git.PullOptions{
+		SingleBranch: true,
+		Force:        true,
 	})
+	if err != nil {
+		if errors.Is(err, git.NoErrAlreadyUpToDate) {
+			log.Info("already up-to-date")
+
+			return true, nil
+		}
+
+		return false, err
+	}
+
+	head, err = r.repo.Head()
+	if err != nil {
+		return false, err
+	}
+	log.Info("updated to", "rev", head.Hash().String())
 
 	return true, nil
 }