on master help sign in
Add utils for git
commit2be58a4ef4a8194f653adb61e9c88915359e7e75 authorLuigy Leon <luigy@outlook.com> dateTue 8 May 2018, 14:29 (8 years ago) parent317c838
5 files changed+24−6
lib/command/obelisk-command.cabal+1 lib/command/src/Obelisk/Command.hs+1 lib/command/src/Obelisk/Command/Deploy.hs+1 lib/command/src/Obelisk/Command/Thunk.hs+2−6 lib/command/src/Obelisk/Command/Utils.hs+19
lib/command/obelisk-command.cabal+1
@@ -39,6 +39,7 @@ library
3939 Obelisk.Command.Repl
4040 Obelisk.Command.Run
4141 Obelisk.Command.Thunk
42+ Obelisk.Command.Utils
4243 -- -fobject-code is so that the StaticPointers extension can work in ghci
4344 ghc-options: -Wall -fobject-code
4445
lib/command/src/Obelisk/Command.hs+1
@@ -26,6 +26,7 @@ import Obelisk.Command.Deploy
2626import Obelisk.Command.Thunk
2727import Obelisk.Command.Repl
2828import Obelisk.Command.Run
29+import Obelisk.Command.Utils
2930
3031data Args = Args
3132 { _args_noHandOffPassed :: Bool
lib/command/src/Obelisk/Command/Deploy.hs+1
@@ -7,6 +7,7 @@ import System.FilePath
77import System.Posix.Files
88import System.Process
99
10+import Obelisk.Command.Utils
1011import Obelisk.Command.Thunk
1112
1213deployInit :: ThunkPtr -> FilePath -> FilePath -> FilePath -> [String] -> IO ()
lib/command/src/Obelisk/Command/Thunk.hs+2−6
@@ -64,6 +64,7 @@ import System.Posix (getSymbolicLinkStatus, modificationTime)
6464import System.Process
6565
6666import Development.Placeholders
67+import Obelisk.Command.Utils
6768
6869--TODO: Support symlinked thunk data
6970data ThunkData
@@ -510,12 +511,7 @@ packThunk thunkDir upstream = readThunk thunkDir >>= \case
510511
511512getThunkPtr :: FilePath -> String -> IO ThunkPtr
512513getThunkPtr thunkDir upstream = do
513− --Check whether the working directory is clean
514− statusOutput <- readProcess "hub"
515− [ "-C", thunkDir
516− , "status", "--porcelain", "--ignored" ] ""
517− diffOutput <- readProcess "hub" [ "-C", thunkDir , "diff" ] ""
518− case null statusOutput && null diffOutput of
514+ checkGitCleanStatus thunkDir >>= \case
519515 False -> do
520516 statusDebug <- readProcess "hub"
521517 [ "-C", thunkDir, "status", "--ignored" ] ""
lib/command/src/Obelisk/Command/Utils.hsnew file+19
@@ -0,0 +1,19 @@
1+module Obelisk.Command.Utils where
2+
3+import System.Process
4+
5+-- Check whether the working directory is clean
6+checkGitCleanStatus :: FilePath -> IO Bool
7+checkGitCleanStatus fp = do
8+ statusOutput <- readProcess "hub"
9+ [ "-C", fp
10+ , "status", "--porcelain", "--ignored" ] ""
11+ diffOutput <- readProcess "hub" [ "-C", fp , "diff" ] ""
12+ return $ null statusOutput && null diffOutput
13+
14+initGit :: FilePath -> IO ()
15+initGit dir = do
16+ let git args = callProcess "git" $ "-C" : dir : args
17+ git ["init"]
18+ git ["add", "."]
19+ git ["commit", "-m", "Initial commit."]