From 39070e1078ac64b7df2677faa0bbf868ee631c38 Mon Sep 17 00:00:00 2001 From: "Yann Esposito (Yogsototh)" Date: Sun, 21 Oct 2018 12:21:57 +0200 Subject: [PATCH] hook handling --- gpm.cabal | 3 ++- src/GPM.hs | 6 ++++++ src/GPM/Hooks.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/GPM/Init.hs | 2 ++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/GPM/Hooks.hs diff --git a/gpm.cabal b/gpm.cabal index 0e2997a..a99648f 100644 --- a/gpm.cabal +++ b/gpm.cabal @@ -2,7 +2,7 @@ -- -- see: https://github.com/sol/hpack -- --- hash: 2181d6cb75bcd17dab9a58fcfa594141af68c4c3e34050da6ce0beeb47bb7642 +-- hash: 04bfdb9ffa855881f6cd6cc09bf3b494a2107ded6cc33c41699546a12526099e name: gpm version: 0.1.0.0 @@ -24,6 +24,7 @@ library GPM GPM.Docs GPM.Helpers + GPM.Hooks GPM.Init GPM.Issue GPM.Review diff --git a/src/GPM.hs b/src/GPM.hs index 8d76b8e..184e54c 100755 --- a/src/GPM.hs +++ b/src/GPM.hs @@ -14,6 +14,7 @@ import Turtle import GPM.Helpers (inGPM) +import qualified GPM.Hooks as Hooks import qualified GPM.Init as Init import qualified GPM.Issue as Issue import qualified GPM.Review as Review @@ -27,11 +28,13 @@ gpm = do NewIssue issueOpt -> inGPM (Issue.handleNewIssue issueOpt) Review reviewCmd -> inGPM (Review.handleReview reviewCmd) Serve serveCmd -> inGPM (Serve.handleServe serveCmd) + Hooks hooksCmd -> inGPM (Hooks.handleHooks hooksCmd) data Command = Init | NewIssue Issue.IssueOptions | Review Review.ReviewCommand | Serve Serve.ServeCommand + | Hooks Hooks.HooksCommand parser :: Parser Command parser = subcommand "init" "Initialize gpm" (pure Init) @@ -44,3 +47,6 @@ parser = subcommand "init" "Initialize gpm" (pure Init) <|> Serve <$> subcommand "serve" "Serve the git to the web" Serve.parseServeCommand + <|> Hooks <$> subcommand "hooks" + "Handle hooks for this git repository" + Hooks.parseHooksCommand diff --git a/src/GPM/Hooks.hs b/src/GPM/Hooks.hs new file mode 100644 index 0000000..c7bf03e --- /dev/null +++ b/src/GPM/Hooks.hs @@ -0,0 +1,46 @@ +{-# LANGUAGE ApplicativeDo #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE OverloadedStrings #-} + +{-| +module : GPM.Helpers +Description : GPM helper functions +License : Public Domain +Maintainer : yann.esposito@gmail.com +-} +module GPM.Hooks + ( init + , handleHooks + , parseHooksCommand + , HooksCommand(..) + ) +where + +import Protolude hiding ((%)) +import Turtle + +import GPM.Helpers + +data HooksCommand = SyncHooks + +parseHooksCommand :: Parser HooksCommand +parseHooksCommand = subcommand "sync" "Synchronize hooks from gpm branch" (pure SyncHooks) + +-- | Init a hook directory with the git hooks +init :: IO () +init = do + green "* hooks/" + putText " Copyings default hooks into the hooks directory" + let hooksDir = "hooks" + cptree (".git" "hooks") hooksDir + debug_ (toS (format ("git add "%fp) hooksDir)) + +-- | Handle hooks related commands +handleHooks :: HooksCommand -> Text -> IO () +handleHooks SyncHooks _ = do + let githooksdir = ".git" "hooks" + gpmhooksdir = "hooks" + putErrText (format (" deleting "%fp) githooksdir) + rmtree githooksdir + putErrText (format (" cp -r "%fp%" "%fp) gpmhooksdir githooksdir) + cptree gpmhooksdir githooksdir diff --git a/src/GPM/Init.hs b/src/GPM/Init.hs index f0a4135..cfd1063 100644 --- a/src/GPM/Init.hs +++ b/src/GPM/Init.hs @@ -21,6 +21,7 @@ import GPM.Helpers (debug_, yellow) import qualified GPM.Issue as Issue import qualified GPM.Review as Review import qualified GPM.Serve as Serve +import qualified GPM.Hooks as Hooks -- | Init a repository with a new empty branch named @gpm@ init :: IO () @@ -30,6 +31,7 @@ init = do Issue.init Docs.init Review.init + Hooks.init Serve.init debug_ "git commit -m 'gpm initialized'" debug_ "git checkout master"