@@ -93,6 +93,11 @@ data ThunkSource
93 | ThunkSource_Git GitSource
93 | ThunkSource_Git GitSource
94 deriving (Show, Eq, Ord)
94 deriving (Show, Eq, Ord)
96+thunkSourceToGitSource :: ThunkSource -> GitSource
97+thunkSourceToGitSource = \case
98+ ThunkSource_GitHub s -> forgetGithub False s
99+ ThunkSource_Git s -> s
96data GitHubSource = GitHubSource
101data GitHubSource = GitHubSource
97 { _gitHubSource_owner :: Name Owner
102 { _gitHubSource_owner :: Name Owner
98 , _gitHubSource_repo :: Name Repo
103 , _gitHubSource_repo :: Name Repo
@@ -463,11 +468,7 @@ updateThunkToLatest (ThunkUpdateConfig mBranch thunkConfig) target = spinner $ d
463 Just branch -> readThunk target >>= \case
468 Just branch -> readThunk target >>= \case
464 Left err -> failWith [i|Thunk update: ${err}|]
469 Left err -> failWith [i|Thunk update: ${err}|]
465 Right c -> case c of
470 Right c -> case c of
466− ThunkData_Packed _ t -> case _thunkPtr_source t of
471+ ThunkData_Packed _ t -> setThunk thunkConfig target (thunkSourceToGitSource $ _thunkPtr_source t) branch
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_Checkout -> failWith [i|Thunk located at ${target} is unpacked. Use 'ob thunk pack' on the desired directory and then try 'ob thunk update' again.|]
472 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.|]
473 spinner = withSpinner' ("Updating thunk " <> T.pack target <> " to latest") (pure $ const $ "Thunk " <> T.pack target <> " updated to latest")
474 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
798 let (thunkParent, thunkName) = splitFileName thunkDir
799 let (thunkParent, thunkName) = splitFileName thunkDir
799 withTempDirectory thunkParent thunkName $ \tmpThunk -> do
800 withTempDirectory thunkParent thunkName $ \tmpThunk -> do
802+ gitSrc = thunkSourceToGitSource $ _thunkPtr_source tptr
801− (gitSrc, newSpec) = case _thunkPtr_source tptr of
803+ newSpec = case _thunkPtr_source tptr of
802− ThunkSource_GitHub s' -> (forgetGithub False s', NonEmpty.head gitHubThunkSpecs)
804+ ThunkSource_GitHub _ -> NonEmpty.head gitHubThunkSpecs
803− ThunkSource_Git s' -> (s', NonEmpty.head gitThunkSpecs)
805+ ThunkSource_Git _ -> NonEmpty.head gitThunkSpecs
804 withSpinner' ("Fetching thunk " <> T.pack thunkName)
806 withSpinner' ("Fetching thunk " <> T.pack thunkName)
805 (finalMsg noTrail $ const $ "Fetched thunk " <> T.pack thunkName) $ do
807 (finalMsg noTrail $ const $ "Fetched thunk " <> T.pack thunkName) $ do
806− let git = callProcessAndLogOutput (Notice, Notice) . gitProc (tmpThunk </> unpackedDirName)
808+ gitCloneForThunkUnpack gitSrc (_thunkRev_commit $ _thunkPtr_rev tptr) (tmpThunk </> unpackedDirName)
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"]
816 createThunk tmpThunk $ Left newSpec
810 createThunk tmpThunk $ Left newSpec
@@ -819,6 +813,22 @@ unpackThunk' noTrail thunkDir = checkThunkDirectory thunkDir *> readThunk thunkD
819 removePathForcibly thunkDir
813 removePathForcibly thunkDir
820 renameDirectory tmpThunk thunkDir
814 renameDirectory tmpThunk thunkDir
816+gitCloneForThunkUnpack
818+ => GitSource -- ^ Git source to use
819+ -> Ref hash -- ^ Commit hash to reset to
820+ -> FilePath -- ^ Directory to clone into
822+gitCloneForThunkUnpack gitSrc commit dir = do
823+ let git = callProcessAndLogOutput (Notice, Notice) . gitProc dir
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"]
823--TODO: add a rollback mode to pack to the original thunk
833--TODO: add a rollback mode to pack to the original thunk
824packThunk :: MonadObelisk m => ThunkPackConfig -> FilePath -> m ThunkPtr
834packThunk :: MonadObelisk m => ThunkPackConfig -> FilePath -> m ThunkPtr
@@ -981,9 +991,7 @@ getThunkPtr gitCheckClean dir mPrivate = do
981-- | Get the latest revision available from the given source
991-- | Get the latest revision available from the given source
982getLatestRev :: MonadObelisk m => ThunkSource -> m ThunkRev
992getLatestRev :: MonadObelisk m => ThunkSource -> m ThunkRev
983getLatestRev os = do
993getLatestRev os = do
984− let gitS = case os of
994+ let gitS = thunkSourceToGitSource os
985− ThunkSource_GitHub s -> forgetGithub False s
986− ThunkSource_Git s -> s
987 (_, commit) <- gitGetCommitBranch (_gitSource_url gitS) (untagName <$> _gitSource_branch gitS)
995 (_, commit) <- gitGetCommitBranch (_gitSource_url gitS) (untagName <$> _gitSource_branch gitS)
988 case os of
996 case os of
989 ThunkSource_GitHub s -> githubThunkRev s commit
997 ThunkSource_GitHub s -> githubThunkRev s commit