Skip to content

Commit

Permalink
feat: check if there are changes found in the git tree (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored Jan 14, 2020
1 parent f79180b commit 8e3da16
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ func run(c config) error {
return xerrors.Errorf("unable to get a worktree based on the given fs: %w", err)
}

s, err := w.Status()
if err != nil {
return xerrors.Errorf("unable to get the working tree status: %w", err)
}

if !s.IsClean() {
return xerrors.New("the repository is dirty: commit all changes before running 'cob'")
}

err = w.Reset(&git.ResetOptions{Commit: *prev, Mode: git.HardReset})
if err != nil {
return xerrors.Errorf("failed to reset the worktree to a previous commit: %w", err)
Expand Down

0 comments on commit 8e3da16

Please sign in to comment.