From b071cd2e45f825484436bfb44fc6960baa729b13 Mon Sep 17 00:00:00 2001 From: Ion Jaureguialzo Sarasola Date: Wed, 16 Oct 2024 00:44:57 +0200 Subject: [PATCH] Reset the repository to the latest commit when updating Resolves #69 --- utils/utils.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 22cf4d4..69122e0 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/go-git/go-git/v5" + "github.com/go-git/go-git/v5/plumbing" ) func RepoDir() string { @@ -146,7 +147,17 @@ func Update() (string, error) { } err = w.Pull(&git.PullOptions{}) if err != nil && err != git.NoErrAlreadyUpToDate { - return "", err + reference, err := r.Reference(plumbing.NewRemoteReferenceName("origin", "main"), false) + if err != nil { + return "", err + } + err = w.Reset(&git.ResetOptions{ + Commit: reference.Hash(), + Mode: git.HardReset, + }) + if err != nil { + return "", err + } } else if err != nil { return "Already up to date", nil }