@@ -93,6 +93,11 @@ data ThunkSource
9393 | ThunkSource_Git GitSource
9494 deriving (Show, Eq, Ord)
9595
96+thunkSourceToGitSource :: ThunkSource -> GitSource
97+thunkSourceToGitSource = \case
98+ ThunkSource_GitHub s -> forgetGithub False s
99+ ThunkSource_Git s -> s
100+
96101data GitHubSource = GitHubSource
97102 { _gitHubSource_owner :: Name Owner
98103 , _gitHubSource_repo :: Name Repo
@@ -803,15 +808,7 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir *> readThunk thunkD
803808 ThunkSource_Git s' -> (s', NonEmpty.head gitThunkSpecs)
804809 withSpinner' ("Fetching thunk " <> T.pack thunkName)
805810 (finalMsg noTrail $ const $ "Fetched thunk " <> T.pack thunkName) $ do
806− let git = callProcessAndLogOutput (Notice, Notice) . gitProc (tmpThunk </> unpackedDirName)
807− git $ [ "clone" ]
808− ++ ["--recursive" | _gitSource_fetchSubmodules gitSrc]
809− ++ [ T.unpack $ gitUriToText $ _gitSource_url gitSrc ]
810− ++ do branch <- maybeToList $ _gitSource_branch gitSrc
811− [ "--branch", T.unpack $ untagName branch ]
812− git ["reset", "--hard", Ref.toHexString $ _thunkRev_commit $ _thunkPtr_rev tptr]
813− when (_gitSource_fetchSubmodules gitSrc) $
814− git ["submodule", "update", "--recursive", "--init"]
811+ gitCloneForThunkUnpack gitSrc (_thunkRev_commit $ _thunkPtr_rev tptr) (tmpThunk </> unpackedDirName)
815812
816813 createThunk tmpThunk $ Left newSpec
817814
@@ -819,6 +816,22 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir *> readThunk thunkD
819816 removePathForcibly thunkDir
820817 renameDirectory tmpThunk thunkDir
821818
819+gitCloneForThunkUnpack
820+ :: MonadObelisk m
821+ => GitSource -- ^ Git source to use
822+ -> Ref hash -- ^ Commit hash to reset to
823+ -> FilePath -- ^ Directory to clone into
824+ -> m ()
825+gitCloneForThunkUnpack gitSrc commit dir = do
826+ let git = callProcessAndLogOutput (Notice, Notice) . gitProc dir
827+ git $ [ "clone" ]
828+ ++ ["--recursive" | _gitSource_fetchSubmodules gitSrc]
829+ ++ [ T.unpack $ gitUriToText $ _gitSource_url gitSrc ]
830+ ++ do branch <- maybeToList $ _gitSource_branch gitSrc
831+ [ "--branch", T.unpack $ untagName branch ]
832+ git ["reset", "--hard", Ref.toHexString commit]
833+ when (_gitSource_fetchSubmodules gitSrc) $
834+ git ["submodule", "update", "--recursive", "--init"]
822835
823836--TODO: add a rollback mode to pack to the original thunk
824837packThunk :: MonadObelisk m => ThunkPackConfig -> FilePath -> m ThunkPtr