diff --git a/gpm.cabal b/gpm.cabal index 6d73dbf..b43ddce 100644 --- a/gpm.cabal +++ b/gpm.cabal @@ -2,7 +2,7 @@ -- -- see: https://github.com/sol/hpack -- --- hash: 33fb8dc1910b29dc2948850dc3ab52f6a6c420a93c0113d1fc81076fcd555c3a +-- hash: c6d39ec4e6cb0558da69c75830e9471b116c0dfabc6cdbaaefa819cea92298b1 name: gpm version: 0.1.0.0 @@ -32,6 +32,7 @@ library build-depends: base >=4.8 && <5 , file-embed + , foldl , protolude , turtle default-language: Haskell2010 @@ -47,6 +48,7 @@ executable gpm build-depends: base >=4.8 && <5 , file-embed + , foldl , gpm , protolude , turtle diff --git a/package.yaml b/package.yaml index b658fd5..c50ff2b 100644 --- a/package.yaml +++ b/package.yaml @@ -27,6 +27,7 @@ dependencies: - protolude - turtle - file-embed +- foldl library: source-dirs: src executables: diff --git a/src/GPM.hs b/src/GPM.hs index 9b78af4..91b7401 100755 --- a/src/GPM.hs +++ b/src/GPM.hs @@ -5,8 +5,10 @@ module GPM where import Data.FileEmbed (embedStringFile) -import Protolude hiding (die, stdout, (%)) +import Protolude hiding (die, stdout, (%),fold) import Turtle +import qualified Control.Foldl as Fold +import Control.Exception.Base (bracket) import GPM.Review (ReviewCommand (..), handleReview, parseReviewCmd) @@ -16,8 +18,8 @@ gpm = do subcmd <- options "Git Project Manager" parser case subcmd of Init -> init - NewIssue -> newIssue - Review reviewCmd -> handleReview reviewCmd + NewIssue -> inGPM newIssue + Review reviewCmd -> inGPM (handleReview reviewCmd) data Command = Init | NewIssue @@ -31,6 +33,21 @@ parser = subcommand "init" "Initialize gpm" (pure Init) "Review (use current branch by default)" parseReviewCmd +inGPM :: MonadIO io => IO a -> io () +inGPM actions = sh $ do + res <- fold (inshell "git rev-parse --abbrev-ref HEAD" empty) Fold.head + oldbr <- case res of + Nothing -> die "Cannot retrieve current branch" + Just br -> do + void $ inshell "git stash --all" empty + void $ inshell "git checkout gpm" empty + return br + liftIO $ bracket (return ()) + (const $ sh $ do + void $ inshell ("git checkout " <> lineToText oldbr) empty + void $ inshell "git stash pop" empty) + (const actions) + newIssue :: IO () newIssue = die "TODO"