@@ -7,7 +7,6 @@
77{-# LANGUAGE PatternGuards #-}
88{-# LANGUAGE ScopedTypeVariables #-}
99{-# LANGUAGE TypeApplications #-}
10−
1110module Obelisk.Command.Thunk
1211 ( ThunkPtr (..)
1312 , ThunkRev (..)
@@ -74,7 +73,7 @@ import System.Process (proc)
7473import Obelisk.App (MonadObelisk)
7574import Obelisk.CliApp (Severity (..), callProcessAndLogOutput, failWith, putLog, readProcessAndLogStderr,
7675 withExitFailMessage, withSpinner)
77−import Obelisk.Command.Utils (checkGitCleanStatus, cp, git, procWithPackages)
76+import Obelisk.Command.Utils (checkGitCleanStatus, gitProc)
7877
7978--TODO: Support symlinked thunk data
8079data ThunkData
@@ -131,7 +130,7 @@ getNixSha256ForUriUnpacked :: MonadObelisk m => URI -> m NixSha256
131130getNixSha256ForUriUnpacked uri =
132131 withExitFailMessage ("nix-prefetch-url: Failed to determine sha256 hash of URL " <> T.pack (show uri)) $ do
133132 fmap T.pack $ readProcessAndLogStderr Debug $
134− procWithPackages ["nix-prefetch-scripts"] "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , show uri]
133+ proc "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , show uri]
135134
136135nixPrefetchGit :: MonadObelisk m => URI -> Text -> Bool -> m NixSha256
137136nixPrefetchGit uri rev fetchSubmodules =
@@ -151,10 +150,10 @@ nixPrefetchGit uri rev fetchSubmodules =
151150getLatestGitRev :: MonadObelisk m => GitSource -> m ThunkRev
152151getLatestGitRev s = withSystemTempDirectory "git-clone" $ \tmpDir -> do
153152 withExitFailMessage ("Unable to determine latest git revision for branch " <> branch) $ do
154− out <- fmap T.pack $ readProcessAndLogStderr Debug $ git tmpDir
155− [ ["clone", "--no-checkout", show $ _gitSource_url s] -- Might be able to use --bare here instead to go faster.
156− , ["log", T.unpack branch, "--max-count=1", "--format=%H"]
157− ]
153+ let git = fmap T.pack . readProcessAndLogStderr Debug . gitProc tmpDir
154+ out <- liftA2 (<>)
155+ (git ["clone", "--no-checkout", show $ _gitSource_url s]) -- Might be able to use --bare here instead to go faster.
156+ (git ["log", T.unpack branch, "--max-count=1", "--format=%H"])
158157
159158 case T.strip <$> safeLast (T.lines out) of
160159 Nothing -> failWith $ "Unable to parse git log: " <> out
@@ -599,7 +598,7 @@ unpackThunk thunkDir = readThunk thunkDir >>= \case
599598 --If this directory already exists then something is weird and we should fail
600599 liftIO $ createDirectory obGitDir
601600 callProcessAndLogOutput (Notice, Error) $
602− cp ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
601+ proc "cp" ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
603602
604603 withSpinner ("Preparing thunk in " <> T.pack thunkDir) $ do
605604 -- Checkout
@@ -615,28 +614,26 @@ unpackThunk thunkDir = readThunk thunkDir >>= \case
615614 forM_ (_gitHubSource_branch s) $ \branch ->
616615 callProcessAndLogOutput (Notice, Error) $
617616 proc "hub" ["-C", tmpRepo, "branch", "-u", "origin/" <> T.unpack (untagName branch)]
618− callProcessAndLogOutput (Notice, Error) $
619− proc "rm" ["-r", thunkDir]
620− callProcessAndLogOutput (Notice, Error) $
621− procWithPackages ["coreutils"] "mv" ["-T", tmpRepo, thunkDir]
617+ callProcessAndLogOutput (Notice, Error) $ proc "rm" ["-r", thunkDir]
618+ callProcessAndLogOutput (Notice, Error) $ proc "mv" ["-T", tmpRepo, thunkDir]
622619
623620 ThunkSource_Git s -> do
624− withSpinner ("Retreiving thunk " <> T.pack thunkName <> " from Git repo") $
625− callProcessAndLogOutput (Notice, Notice) $ git tmpRepo
626− [ ["clone", if _gitSource_fetchSubmodules s then "--recursive" else "", show (_gitSource_url s)]
627− , ["reset", "--hard", Ref.toHexString $ _thunkRev_commit $ _thunkPtr_rev tptr]
628− , if _gitSource_fetchSubmodules s then ["submodule", "update", "--recursive"] else []
629− , ["branch", "-u", "origin/" <> T.unpack (untagName $ _gitSource_branch s)]
630− ]
621+ withSpinner ("Retreiving thunk " <> T.pack thunkName <> " from Git repo") $ do
622+ let git = callProcessAndLogOutput (Notice, Notice) . gitProc tmpRepo
623+ git ["clone", if _gitSource_fetchSubmodules s then "--recursive" else "", show (_gitSource_url s)]
624+ git ["reset", "--hard", Ref.toHexString $ _thunkRev_commit $ _thunkPtr_rev tptr]
625+ when (_gitSource_fetchSubmodules s) $
626+ git ["submodule", "update", "--recursive", "--init"]
627+ git ["branch", "-u", "origin/" <> T.unpack (untagName $ _gitSource_branch s)]
631628
632629 withSpinner ("Preparing thunk in " <> T.pack thunkDir) $ do
633630 liftIO $ createDirectory obGitDir
634631 callProcessAndLogOutput (Notice, Error) $
635− cp ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
632+ proc "cp" ["-r", "-T", thunkDir </> ".", obGitDir </> "orig-thunk"]
636633 callProcessAndLogOutput (Notice, Error) $
637634 proc "rm" ["-r", thunkDir]
638635 callProcessAndLogOutput (Notice, Error) $
639− procWithPackages ["coreutils"] "mv" ["-T", tmpRepo, thunkDir]
636+ proc "mv" ["-T", tmpRepo, thunkDir]
640637
641638--TODO: add force mode to pack even if changes are present
642639--TODO: add a rollback mode to pack to the original thunk
@@ -661,8 +658,7 @@ getThunkPtr' :: MonadObelisk m => Bool -> FilePath -> Text -> m ThunkPtr
661658getThunkPtr' checkClean thunkDir upstream = do
662659 when checkClean $ checkGitCleanStatus thunkDir >>= \case
663660 False -> do
664− statusDebug <- fmap T.pack $ readProcessAndLogStderr Notice $
665− git thunkDir [["status", "--ignored"]]
661+ statusDebug <- readGitProcess thunkDir ["status", "--ignored"]
666662 putLog Warning "cannot proceed with unsaved working copy (git status):"
667663 putLog Notice statusDebug
668664 failWith "thunk pack: thunk checkout contains unsaved modifications"
@@ -795,4 +791,4 @@ parseSshShorthand uri = do
795791
796792
797793readGitProcess :: MonadObelisk m => FilePath -> [String] -> m Text
798−readGitProcess repo args = fmap T.pack $ readProcessAndLogStderr Notice $ git repo [args]
794+readGitProcess repo = fmap T.pack . readProcessAndLogStderr Notice . gitProc repo