From 9d975e9ee4c44782da0815fb161ea8676dbf559c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 23 Nov 2014 18:48:52 -0400 Subject: add --merge --- src/Propellor/Spin.hs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'src/Propellor/Spin.hs') diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 8606013a..9e8e145f 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -2,7 +2,8 @@ module Propellor.Spin ( commitSpin, spin, update, - gitPushHelper + gitPushHelper, + mergeSpin, ) where import Data.List @@ -27,7 +28,7 @@ import Utility.SafeCommand commitSpin :: IO () commitSpin = do void $ actionMessage "Git commit" $ - gitCommit [Param "--allow-empty", Param "-a", Param "-m", Param "propellor spin"] + gitCommit [Param "--allow-empty", Param "-a", Param "-m", Param spinCommitMessage] -- Push to central origin repo first, if possible. -- The remote propellor will pull from there, which avoids -- us needing to send stuff directly to the remote host. @@ -269,3 +270,30 @@ gitPushHelper hin hout = void $ fromstdin `concurrently` tostdout B.hPut toh b hFlush toh connect fromh toh + +mergeSpin :: IO () +mergeSpin = do + branch <- getCurrentBranch + branchref <- getCurrentBranchRef + old_head <- getCurrentGitSha1 branch + old_commit <- findLastNonSpinCommit + rungit "reset" [Param old_commit] + rungit "commit" [Param "-a"] + rungit "merge" =<< gpgSignParams [Param "-s", Param "ours", Param old_head] + current_commit <- getCurrentGitSha1 branch + rungit "update-ref" [Param branchref, Param current_commit] + rungit "checkout" [Param branch] + where + rungit cmd ps = unlessM (boolSystem "git" (Param cmd:ps)) $ + error ("git " ++ cmd ++ " failed") + +findLastNonSpinCommit :: IO String +findLastNonSpinCommit = do + commits <- map (separate (== ' ')) . lines + <$> readProcess "git" ["log", "--oneline", "--no-abbrev-commit"] + case dropWhile (\(_, msg) -> msg == spinCommitMessage) commits of + ((sha, _):_) -> return sha + _ -> error $ "Did not find any previous commit that was not a " ++ show spinCommitMessage + +spinCommitMessage :: String +spinCommitMessage = "propellor spin" -- cgit v1.2.3