on master help sign in
Add utils for git
2be58a4Luigy Leon
lib/command/obelisk-command.cabal+1
@@ -39,6 +39,7 @@ library
39 Obelisk.Command.Repl
39 Obelisk.Command.Repl
40 Obelisk.Command.Run
40 Obelisk.Command.Run
41 Obelisk.Command.Thunk
41 Obelisk.Command.Thunk
42+ Obelisk.Command.Utils
42 -- -fobject-code is so that the StaticPointers extension can work in ghci
43 -- -fobject-code is so that the StaticPointers extension can work in ghci
43 ghc-options: -Wall -fobject-code
44 ghc-options: -Wall -fobject-code
44
45
lib/command/src/Obelisk/Command.hs+1
@@ -26,6 +26,7 @@ import Obelisk.Command.Deploy
26import Obelisk.Command.Thunk
26import Obelisk.Command.Thunk
27import Obelisk.Command.Repl
27import Obelisk.Command.Repl
28import Obelisk.Command.Run
28import Obelisk.Command.Run
29+import Obelisk.Command.Utils
29
30
30data Args = Args
31data Args = Args
31 { _args_noHandOffPassed :: Bool
32 { _args_noHandOffPassed :: Bool
lib/command/src/Obelisk/Command/Deploy.hs+1
@@ -7,6 +7,7 @@ import System.FilePath
7import System.Posix.Files
7import System.Posix.Files
8import System.Process
8import System.Process
9
9
10+import Obelisk.Command.Utils
10import Obelisk.Command.Thunk
11import Obelisk.Command.Thunk
11
12
12deployInit :: ThunkPtr -> FilePath -> FilePath -> FilePath -> [String] -> IO ()
13deployInit :: ThunkPtr -> FilePath -> FilePath -> FilePath -> [String] -> IO ()
lib/command/src/Obelisk/Command/Thunk.hs+2−6
@@ -64,6 +64,7 @@ import System.Posix (getSymbolicLinkStatus, modificationTime)
64import System.Process
64import System.Process
65
65
66import Development.Placeholders
66import Development.Placeholders
67+import Obelisk.Command.Utils
67
68
68--TODO: Support symlinked thunk data
69--TODO: Support symlinked thunk data
69data ThunkData
70data ThunkData
@@ -510,12 +511,7 @@ packThunk thunkDir upstream = readThunk thunkDir >>= \case
510
511
511getThunkPtr :: FilePath -> String -> IO ThunkPtr
512getThunkPtr :: FilePath -> String -> IO ThunkPtr
512getThunkPtr thunkDir upstream = do
513getThunkPtr thunkDir upstream = do
513− --Check whether the working directory is clean
514+ checkGitCleanStatus thunkDir >>= \case
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
519 False -> do
515 False -> do
520 statusDebug <- readProcess "hub"
516 statusDebug <- readProcess "hub"
521 [ "-C", thunkDir, "status", "--ignored" ] ""
517 [ "-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."]