diff options
author | Alan Pearce | 2024-06-26 10:32:36 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-26 10:32:36 +0200 |
commit | fb23114666d22afcd036b955fcd1b27f3e60d0e7 (patch) | |
tree | 3320b950df1473fcd72e468e9f1b7c795d803e22 /internal/vcs/repository.go | |
parent | 59a3323f6eec9d0b38d2c10ccf514f83ca12b419 (diff) | |
download | website-fb23114666d22afcd036b955fcd1b27f3e60d0e7.tar.lz website-fb23114666d22afcd036b955fcd1b27f3e60d0e7.tar.zst website-fb23114666d22afcd036b955fcd1b27f3e60d0e7.zip |
fix repository not updating
Diffstat (limited to 'internal/vcs/repository.go')
-rw-r--r-- | internal/vcs/repository.go | 38 |
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 } |