@@ -11,10 +11,13 @@ where
11
11
import Control.Concurrent.STM (atomically )
12
12
import Control.Concurrent.STM.TVar (modifyTVar' , newTVarIO , readTVar , readTVarIO )
13
13
import Data.List.NonEmpty (pattern (:|) )
14
+ import Data.Set qualified as Set
14
15
import System.Console.Regions qualified as Console.Regions
15
16
import System.IO.Unsafe (unsafePerformIO )
16
17
import U.Codebase.HashTags (CausalHash )
18
+ import U.Codebase.Sqlite.Queries qualified as Q
17
19
import U.Codebase.Sqlite.Queries qualified as Queries
20
+ import U.Codebase.Sqlite.RemoteProjectBranch qualified as SqliteRPB
18
21
import Unison.Cli.Monad (Cli )
19
22
import Unison.Cli.Monad qualified as Cli
20
23
import Unison.Cli.Share.Projects qualified as Share
@@ -77,9 +80,15 @@ downloadProjectBranchFromShare useSquashed branch =
77
80
Cli. respond (Output. DownloadedEntities numDownloaded)
78
81
SyncV2 -> do
79
82
let branchRef = SyncV2. BranchRef (into @ Text (ProjectAndBranch branch. projectName remoteProjectBranchName))
80
- let downloadedCallback = \ _ -> pure ()
81
83
let shouldValidate = not $ Codeserver. isCustomCodeserver Codeserver. defaultCodeserver
82
- result <- SyncV2. syncFromCodeserver shouldValidate Share. hardCodedBaseUrl branchRef causalHashJwt downloadedCallback
84
+ knownRemoteHash <- fmap (fromMaybe Set. empty) . Cli. runTransaction $ runMaybeT do
85
+ lastKnownCausalHashId <- SqliteRPB. lastKnownCausalHash <$> MaybeT (Q. loadRemoteBranch branch. projectId Share. hardCodedUri branch. branchId)
86
+ lastKnownCausalHash <- lift $ Q. expectCausalHash lastKnownCausalHashId
87
+ -- Check that we actually have this causal saved.
88
+ lift (Q. checkBranchExistsForCausalHash lastKnownCausalHash) >>= \ case
89
+ True -> pure (Set. singleton lastKnownCausalHash)
90
+ False -> pure mempty
91
+ result <- SyncV2. syncFromCodeserver shouldValidate Share. hardCodedBaseUrl branchRef causalHashJwt knownRemoteHash
83
92
result & onLeft \ err0 -> do
84
93
done case err0 of
85
94
Share. SyncError pullErr ->
0 commit comments