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
|
-- see: https://github.com/sol/hpack
|
||||||
--
|
--
|
||||||
-- hash: 33fb8dc1910b29dc2948850dc3ab52f6a6c420a93c0113d1fc81076fcd555c3a
|
-- hash: c6d39ec4e6cb0558da69c75830e9471b116c0dfabc6cdbaaefa819cea92298b1
|
||||||
|
|
||||||
name: gpm
|
name: gpm
|
||||||
version: 0.1.0.0
|
version: 0.1.0.0
|
||||||
|
@ -32,6 +32,7 @@ library
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.8 && <5
|
base >=4.8 && <5
|
||||||
, file-embed
|
, file-embed
|
||||||
|
, foldl
|
||||||
, protolude
|
, protolude
|
||||||
, turtle
|
, turtle
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
|
@ -47,6 +48,7 @@ executable gpm
|
||||||
build-depends:
|
build-depends:
|
||||||
base >=4.8 && <5
|
base >=4.8 && <5
|
||||||
, file-embed
|
, file-embed
|
||||||
|
, foldl
|
||||||
, gpm
|
, gpm
|
||||||
, protolude
|
, protolude
|
||||||
, turtle
|
, turtle
|
||||||
|
|
|
@ -27,6 +27,7 @@ dependencies:
|
||||||
- protolude
|
- protolude
|
||||||
- turtle
|
- turtle
|
||||||
- file-embed
|
- file-embed
|
||||||
|
- foldl
|
||||||
library:
|
library:
|
||||||
source-dirs: src
|
source-dirs: src
|
||||||
executables:
|
executables:
|
||||||
|
|
23
src/GPM.hs
23
src/GPM.hs
|
@ -5,8 +5,10 @@ module GPM
|
||||||
where
|
where
|
||||||
|
|
||||||
import Data.FileEmbed (embedStringFile)
|
import Data.FileEmbed (embedStringFile)
|
||||||
import Protolude hiding (die, stdout, (%))
|
import Protolude hiding (die, stdout, (%),fold)
|
||||||
import Turtle
|
import Turtle
|
||||||
|
import qualified Control.Foldl as Fold
|
||||||
|
import Control.Exception.Base (bracket)
|
||||||
|
|
||||||
import GPM.Review (ReviewCommand (..), handleReview,
|
import GPM.Review (ReviewCommand (..), handleReview,
|
||||||
parseReviewCmd)
|
parseReviewCmd)
|
||||||
|
@ -16,8 +18,8 @@ gpm = do
|
||||||
subcmd <- options "Git Project Manager" parser
|
subcmd <- options "Git Project Manager" parser
|
||||||
case subcmd of
|
case subcmd of
|
||||||
Init -> init
|
Init -> init
|
||||||
NewIssue -> newIssue
|
NewIssue -> inGPM newIssue
|
||||||
Review reviewCmd -> handleReview reviewCmd
|
Review reviewCmd -> inGPM (handleReview reviewCmd)
|
||||||
|
|
||||||
data Command = Init
|
data Command = Init
|
||||||
| NewIssue
|
| NewIssue
|
||||||
|
@ -31,6 +33,21 @@ parser = subcommand "init" "Initialize gpm" (pure Init)
|
||||||
"Review (use current branch by default)"
|
"Review (use current branch by default)"
|
||||||
parseReviewCmd
|
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 :: IO ()
|
||||||
newIssue = die "TODO"
|
newIssue = die "TODO"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue