Created a safe inGPM function (branch)

This commit is contained in:
Yann Esposito (Yogsototh) 2018-08-31 22:43:19 +02:00
parent e9f057db55
commit e95f7c7701
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 24 additions and 4 deletions

View file

@ -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

View file

@ -27,6 +27,7 @@ dependencies:
- protolude
- turtle
- file-embed
- foldl
library:
source-dirs: src
executables:

View file

@ -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"