From 6bacac7f38f60945527f148644d3f9eba70b4bf5 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 16:50:19 -0700 Subject: implement two pre-spin safety checks - check that we're on the branch specified in git config value propellor.spin-branch - check that there are no uncommitted changes if git config value propellor.forbid-dirty-spin is true Signed-off-by: Sean Whitton (cherry picked from commit 8f374d73ae5b2bb53f82835c6d6b5c0194590006) --- src/Propellor/Spin.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index ae7e7af5..f01975c9 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -32,6 +32,24 @@ import Utility.SafeCommand commitSpin :: IO () commitSpin = do + -- safety check #1: check we're on the configured spin branch + spinBranch <- getGitConfigValue "propellor.spin-branch" + case spinBranch of + Nothing -> return () -- just a noop + Just b -> do + currentBranch <- getCurrentBranch + when (b /= currentBranch) $ error + ("spin aborted: check out branch " + ++ b ++ " first") + + -- safety check #2: check we can commit with a dirty tree + noDirtySpin <- getGitConfigBool "propellor.forbid-dirty-spin" + when noDirtySpin $ do + status <- takeWhile (/= '\n') + <$> readProcess "git" ["status", "--porcelain"] + when (not . null $ status) $ + error "spin aborted: commit changes first" + void $ actionMessage "Git commit" $ gitCommit (Just spinCommitMessage) [Param "--allow-empty", Param "-a"] -- cgit v1.3-2-g0d8e From 5c261fd69be879f3458128398bb6fbb605fb2e1a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 16:56:07 -0700 Subject: tweak wrong spin branch error message Signed-off-by: Sean Whitton (cherry picked from commit 9d44dcd39bb88408ed4cfc94a7b4dfa34a1b5591) --- src/Propellor/Spin.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index f01975c9..bda146cc 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -38,9 +38,9 @@ commitSpin = do Nothing -> return () -- just a noop Just b -> do currentBranch <- getCurrentBranch - when (b /= currentBranch) $ error - ("spin aborted: check out branch " - ++ b ++ " first") + when (b /= currentBranch) $ + error ("spin aborted: check out " + ++ b ++ " branch first") -- safety check #2: check we can commit with a dirty tree noDirtySpin <- getGitConfigBool "propellor.forbid-dirty-spin" -- cgit v1.3-2-g0d8e