diff --git a/onstatic/handler.go b/onstatic/handler.go index 9ebd11b..40c07ac 100644 --- a/onstatic/handler.go +++ b/onstatic/handler.go @@ -20,6 +20,7 @@ func RegisterHandler(s *http.ServeMux) { "/unregister": http.HandlerFunc(handleUnregister), "/": http.HandlerFunc(handleAll), } { + path, handler := path, handler handle := handler if conf.Variables.AccessLog { handle = func(rw http.ResponseWriter, r *http.Request) { diff --git a/onstatic/service.go b/onstatic/service.go index 62ef0c5..512c6b0 100644 --- a/onstatic/service.go +++ b/onstatic/service.go @@ -2,6 +2,7 @@ package onstatic import ( "crypto/sha1" + "errors" "fmt" "io/ioutil" "os" @@ -217,19 +218,22 @@ func doGitPull(repo *git.Repository, branchName string) error { return failure.Wrap(err) } - opt := &git.PullOptions{ + err = repo.Fetch(&git.FetchOptions{ RemoteName: originName, Auth: auth, Force: true, + }) + if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) { + return failure.Wrap(err) } - if branchName != "" { - opt.ReferenceName = plumbing.NewBranchReferenceName(branchName) - } - - err = w.Pull(opt) + err = w.Checkout(&git.CheckoutOptions{ + Branch: plumbing.NewRemoteReferenceName(originName, branchName), + Force: true, + }) if err != nil { return failure.Wrap(err) } + return nil }