From 8e3da165eb46ae73ee6afdd54ef3847dc319d4cc Mon Sep 17 00:00:00 2001 From: Teppei Fukuda Date: Tue, 14 Jan 2020 15:23:45 +0200 Subject: [PATCH] feat: check if there are changes found in the git tree (#3) --- main.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main.go b/main.go index 5032d25..11b80fb 100644 --- a/main.go +++ b/main.go @@ -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)