Check worktree clean when pulling
continuous-integration/drone/push Build is passing Details

This commit is contained in:
SeraphJACK 2024-02-14 00:30:41 +08:00
parent 8236bb37f0
commit e409bbb342
Signed by: SeraphJACK
GPG Key ID: B4FFEA56F3BE0D0C
1 changed files with 16 additions and 4 deletions

View File

@ -9,6 +9,8 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport/http"
)
var ErrWorktreeNotClean = errors.New("worktree is not clean")
const Path = "./beancount"
var repo *git.Repository
@ -46,10 +48,20 @@ func pull() error {
if err != nil {
return err
}
err = w.Pull(&git.PullOptions{Auth: &http.BasicAuth{
Username: config.Cfg.Username,
Password: config.Cfg.Password,
}})
err = w.Pull(&git.PullOptions{
Force: true,
Auth: &http.BasicAuth{
Username: config.Cfg.Username,
Password: config.Cfg.Password,
},
})
status, err := w.Status()
if err != nil {
return err
}
if !status.IsClean() {
return ErrWorktreeNotClean
}
if err != nil && !errors.Is(err, git.NoErrAlreadyUpToDate) {
return err
}