@@ -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
@@ -463,11 +468,7 @@ updateThunkToLatest (ThunkUpdateConfig mBranch thunkConfig) target = spinner $ d
463468 Just branch -> readThunk target >>= \case
464469 Left err -> failWith [i|Thunk update: ${err}|]
465470 Right c -> case c of
466− ThunkData_Packed _ t -> case _thunkPtr_source t of
467− ThunkSource_Git tsg -> setThunk thunkConfig target tsg branch
468− ThunkSource_GitHub tsgh -> do
469− let tsg = forgetGithub False tsgh
470− setThunk thunkConfig target tsg branch
471+ ThunkData_Packed _ t -> setThunk thunkConfig target (thunkSourceToGitSource $ _thunkPtr_source t) branch
471472 ThunkData_Checkout -> failWith [i|Thunk located at ${target} is unpacked. Use 'ob thunk pack' on the desired directory and then try 'ob thunk update' again.|]
472473 where
473474 spinner = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest")
@@ -798,20 +799,13 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir *> readThunk thunkD
798799 let (thunkParent, thunkName) = splitFileName thunkDir
799800 withTempDirectory thunkParent thunkName $ \tmpThunk -> do
800801 let
801− (gitSrc, newSpec) = case _thunkPtr_source tptr of
802− ThunkSource_GitHub s' -> (forgetGithub False s', NonEmpty.head gitHubThunkSpecs)
803− ThunkSource_Git s' -> (s', NonEmpty.head gitThunkSpecs)
802+ gitSrc = thunkSourceToGitSource $ _thunkPtr_source tptr
803+ newSpec = case _thunkPtr_source tptr of
804+ ThunkSource_GitHub _ -> NonEmpty.head gitHubThunkSpecs
805+ ThunkSource_Git _ -> NonEmpty.head gitThunkSpecs
804806 withSpinner' ("Fetching thunk " <> T.pack thunkName)
805807 (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"]
808+ gitCloneForThunkUnpack gitSrc (_thunkRev_commit $ _thunkPtr_rev tptr) (tmpThunk </> unpackedDirName)
815809
816810 createThunk tmpThunk $ Left newSpec
817811
@@ -819,6 +813,22 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir *> readThunk thunkD
819813 removePathForcibly thunkDir
820814 renameDirectory tmpThunk thunkDir
821815
816+gitCloneForThunkUnpack
817+ :: MonadObelisk m
818+ => GitSource -- ^ Git source to use
819+ -> Ref hash -- ^ Commit hash to reset to
820+ -> FilePath -- ^ Directory to clone into
821+ -> m ()
822+gitCloneForThunkUnpack gitSrc commit dir = do
823+ let git = callProcessAndLogOutput (Notice, Notice) . gitProc dir
824+ git $ [ "clone" ]
825+ ++ ["--recursive" | _gitSource_fetchSubmodules gitSrc]
826+ ++ [ T.unpack $ gitUriToText $ _gitSource_url gitSrc ]
827+ ++ do branch <- maybeToList $ _gitSource_branch gitSrc
828+ [ "--branch", T.unpack $ untagName branch ]
829+ git ["reset", "--hard", Ref.toHexString commit]
830+ when (_gitSource_fetchSubmodules gitSrc) $
831+ git ["submodule", "update", "--recursive", "--init"]
822832
823833--TODO: add a rollback mode to pack to the original thunk
824834packThunk :: MonadObelisk m => ThunkPackConfig -> FilePath -> m ThunkPtr
@@ -981,9 +991,7 @@ getThunkPtr gitCheckClean dir mPrivate = do
981991-- | Get the latest revision available from the given source
982992getLatestRev :: MonadObelisk m => ThunkSource -> m ThunkRev
983993getLatestRev os = do
984− let gitS = case os of
985− ThunkSource_GitHub s -> forgetGithub False s
986− ThunkSource_Git s -> s
994+ let gitS = thunkSourceToGitSource os
987995 (_, commit) <- gitGetCommitBranch (_gitSource_url gitS) (untagName <$> _gitSource_branch gitS)
988996 case os of
989997 ThunkSource_GitHub s -> githubThunkRev s commit