From 09085c76d76f708361e3670eb6726671ed1ba845 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 16:48:15 -0700 Subject: implement getGitConfigValue & getGitConfigBool Signed-off-by: Sean Whitton (cherry picked from commit 1828c6d987f9d499b95610311379dcbdeaa21e33) --- src/Propellor/Git.hs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs index a4418340..e11528fa 100644 --- a/src/Propellor/Git.hs +++ b/src/Propellor/Git.hs @@ -29,6 +29,27 @@ setRepoUrl url = do void $ boolSystem "git" [Param "config", Param (branchval "remote"), Param "origin"] void $ boolSystem "git" [Param "config", Param (branchval "merge"), Param $ "refs/heads/"++branch] +getGitConfigValue :: String -> IO (Maybe String) +getGitConfigValue key = do + value <- catchMaybeIO $ + takeWhile (/= '\n') + <$> readProcess "git" ["config", key] + return $ case value of + Just v | not (null v) -> Just v + _ -> Nothing + +-- `git config --bool propellor.blah` outputs "false" if propellor.blah is unset +-- i.e. the git convention is that the default value of any git-config setting +-- is "false". So we don't need a Maybe Bool here. +getGitConfigBool :: String -> IO Bool +getGitConfigBool key = do + value <- catchMaybeIO $ + takeWhile (/= '\n') + <$> readProcess "git" ["config", "--bool", key] + return $ case value of + Just "true" -> True + _ -> False + getRepoUrl :: IO (Maybe String) getRepoUrl = getM get urls where -- cgit v1.2.3 From 0dab06c92cfef9f46d2e99b9207dba97450d5953 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 16:48:48 -0700 Subject: rewrite getRepoUrl with getGitConfigValue Signed-off-by: Sean Whitton (cherry picked from commit 3d4c34dece4d295a349ac5b24ec1fbbd3e90f668) --- src/Propellor/Git.hs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs index e11528fa..a2f5aef2 100644 --- a/src/Propellor/Git.hs +++ b/src/Propellor/Git.hs @@ -51,16 +51,9 @@ getGitConfigBool key = do _ -> False getRepoUrl :: IO (Maybe String) -getRepoUrl = getM get urls +getRepoUrl = getM getGitConfigValue urls where urls = ["remote.deploy.url", "remote.origin.url"] - get u = do - v <- catchMaybeIO $ - takeWhile (/= '\n') - <$> readProcess "git" ["config", u] - return $ case v of - Just url | not (null url) -> Just url - _ -> Nothing hasOrigin :: IO Bool hasOrigin = catchDefaultIO False $ do -- cgit v1.2.3 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(+) 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.2.3 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(-) 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.2.3 From f7aa28042aa11957699d98031df052955f9d987e Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 17:04:22 -0700 Subject: document two new safety checks Signed-off-by: Sean Whitton (cherry picked from commit bf8af2d2dd3c5b08d53bef72d2dc0ae745d81f0c) --- doc/usage.mdwn | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/usage.mdwn b/doc/usage.mdwn index 4eed5416..57be293d 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -124,6 +124,12 @@ other debugging information. `git config propellor.debug 1` will configure propellor to output debugging information. +`git config propellor.spin-branch foo` will configure propellor to refuse to +spin when the foo branch is not checked out. + +`git config propellor.forbid-dirty-spin true` will configure propellor to refuse +to spin when there are uncommitted changes in the `~/.propellor` repository. + The usual git configuration controls which centralized repository (if any) propellor pushes and pulls from. -- cgit v1.2.3 From 6e179823b0a4281ee3b62e401288a1623398edb0 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 6 Dec 2015 17:04:36 -0700 Subject: typo (cherry picked from commit 4e1f83fcd976a8838f3abe10c0e30022ebe83cf3) --- doc/usage.mdwn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/usage.mdwn b/doc/usage.mdwn index 57be293d..16e559fa 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -105,7 +105,7 @@ and configured in haskell. * propellor --check - If propellor is able to run, this simply exists successfully. + If propellor is able to run, this simply exits successfully. * propellor hostname -- cgit v1.2.3 From 39c0073d2800e23b051188de239efdea9b17793e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 8 Dec 2015 12:00:33 -0400 Subject: changelog --- debian/changelog | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/debian/changelog b/debian/changelog index 88a8543b..1f3706f5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +propellor (2.15.1) UNRELEASED; urgency=medium + + * Added git configs propellor.spin-branch and propellor.forbid-dirty-spin. + Thanks, Sean Whitton. + + -- Joey Hess Tue, 08 Dec 2015 11:59:43 -0400 + propellor (2.15.0) unstable; urgency=medium * Added UncheckedProperty type, along with unchecked to indicate a -- cgit v1.2.3