diff --git a/storage.go b/storage.go index 7139050..5d55eaf 100644 --- a/storage.go +++ b/storage.go @@ -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") } }