master
Jan-Lukas Else 2020-03-20 15:32:36 +01:00
parent 82d9057b10
commit f4bac41d11
1 changed files with 7 additions and 1 deletions

View File

@ -48,7 +48,7 @@ func (g Git) init() (r *git.Repository, w *git.Worktree, err error) {
}
if err != nil {
// Delete old things
_ = os.RemoveAll(g.filepath)
g.destroyRepo()
// Clone
r, err = git.PlainClone(g.filepath, false, &git.CloneOptions{
Auth: &gitHttp.BasicAuth{
@ -72,6 +72,10 @@ func (g Git) init() (r *git.Repository, w *git.Worktree, err error) {
return
}
func (g Git) destroyRepo() {
_ = os.RemoveAll(g.filepath)
}
func (g Git) push(repository *git.Repository) error {
err := repository.Push(&git.PushOptions{
Auth: &gitHttp.BasicAuth{
@ -82,6 +86,8 @@ func (g Git) push(repository *git.Repository) error {
if err == nil || err == git.NoErrAlreadyUpToDate {
return nil
} else {
// Destroy repo to prevent errors when trying to create same post again
g.destroyRepo()
return errors.New("failed to push to remote")
}
}