Created a safe inGPM function (branch)
This commit is contained in:
parent
e9f057db55
commit
e95f7c7701
3 changed files with 24 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -27,6 +27,7 @@ dependencies:
|
|||
- protolude
|
||||
- turtle
|
||||
- file-embed
|
||||
- foldl
|
||||
library:
|
||||
source-dirs: src
|
||||
executables:
|
||||
|
|
23
src/GPM.hs
23
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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue