diff options
author | Alan Pearce | 2024-07-10 07:34:34 +0200 |
---|---|---|
committer | Alan Pearce | 2024-07-10 07:34:34 +0200 |
commit | 78ce820690243ed1196159543a61eeafa28c99fb (patch) | |
tree | 03a5c24d3f41b71c7d0650a59ac1fe6ae1ff4c56 | |
parent | bfc935f6ea7b00c539192e486936b8ffbb5a403e (diff) | |
download | website-78ce820690243ed1196159543a61eeafa28c99fb.tar.lz website-78ce820690243ed1196159543a61eeafa28c99fb.tar.zst website-78ce820690243ed1196159543a61eeafa28c99fb.zip |
use fetch + checkout instead of pull
-rw-r--r-- | internal/vcs/repository.go | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/internal/vcs/repository.go b/internal/vcs/repository.go index e034ea4..5950e53 100644 --- a/internal/vcs/repository.go +++ b/internal/vcs/repository.go @@ -7,6 +7,7 @@ import ( "go.alanpearce.eu/x/log" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" "gitlab.com/tozd/go/errors" ) @@ -61,13 +62,8 @@ func (r *Repository) Update() (bool, error) { } r.log.Info("updating from", "rev", head.Hash().String()) - wt, err := r.repo.Worktree() - if err != nil { - return false, err - } - err = wt.Pull(&git.PullOptions{ - SingleBranch: true, - Force: true, + err = r.repo.Fetch(&git.FetchOptions{ + Prune: true, }) if err != nil { if errors.Is(err, git.NoErrAlreadyUpToDate) { @@ -79,11 +75,31 @@ func (r *Repository) Update() (bool, error) { return false, err } - head, err = r.repo.Head() + rem, err := r.repo.Remote("origin") if err != nil { return false, err } - r.log.Info("updated to", "rev", head.Hash().String()) + refs, err := rem.List(&git.ListOptions{ + Timeout: 5, + }) + + var hash plumbing.Hash + for _, ref := range refs { + if ref.Name() == plumbing.Main { + hash = ref.Hash() + } + } + + wt, err := r.repo.Worktree() + if err != nil { + return false, err + } + wt.Checkout(&git.CheckoutOptions{ + Hash: hash, + Force: true, + }) + + r.log.Info("updated to", "rev", hash) return true, r.Clean(wt) } |