Skip to content

Commit

Permalink
Reset the repository to the latest commit when updating
Browse files Browse the repository at this point in the history
Resolves #69
  • Loading branch information
ijaureguialzo committed Oct 15, 2024
1 parent 3744aae commit b071cd2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
)

func RepoDir() string {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b071cd2

Please sign in to comment.