Skip to content

Commit 8825201

Browse files
committed
lore-revision: Fix branch latest update on explicit remote sync
When sync targets an explicit revision with --remote, propagate the remote search location into branch latest maintenance and store latest on the post-sync branch instead of the pre-sync branch. Fixes #122
1 parent 5a9fd5e commit 8825201

2 files changed

Lines changed: 62 additions & 12 deletions

File tree

lore-revision/src/revision/sync.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ pub async fn sync(
316316

317317
let mut revision;
318318
if let Some(revision_string) = options.revision.as_ref() {
319+
location = match execution_context().globals().search_location() {
320+
revision::ResolveSearchLocation::Remote => LoreBranchLocation::Remote,
321+
revision::ResolveSearchLocation::Local
322+
| revision::ResolveSearchLocation::RemoteOrLocal => LoreBranchLocation::Local,
323+
};
319324
revision = revision::resolve(
320325
repository.clone(),
321326
revision_string,
@@ -632,14 +637,14 @@ pub async fn sync(
632637
if location == LoreBranchLocation::Remote {
633638
branch::store_latest(
634639
repository.clone(),
635-
branch_id,
640+
synced_branch,
636641
revision,
637642
BranchLatestStatus::Convergent,
638643
)
639644
.await
640645
.internal("Failed to store revision as current branch latest")?;
641646

642-
branch::store_last_sync(repository, branch_id, revision).await;
647+
branch::store_last_sync(repository, synced_branch, revision).await;
643648
}
644649
}
645650

lore-revision/tests/sync.rs

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ mod tests {
1414
use lore_revision::commit;
1515
use lore_revision::commit::CommitOptions;
1616
use lore_revision::file;
17+
use lore_revision::instance;
18+
use lore_revision::interface::ExecutionContext;
1719
use lore_revision::interface::LoreArray;
1820
use lore_revision::interface::LoreString;
1921
use lore_revision::lore::RepositoryId;
2022
use lore_revision::node::NodeFlags;
23+
use lore_revision::relay::EventDispatcher;
2124
use lore_revision::repository;
2225
use lore_revision::revision::sync;
2326
use lore_revision::revision::sync::SyncOptions;
@@ -134,7 +137,11 @@ mod tests {
134137
.await
135138
.expect("Failed to commit revision");
136139

137-
// Sync back to first revision
140+
let (_current_revision, branch_id) = instance::load_current_anchor(&repository)
141+
.await
142+
.expect("Failed to load current anchor");
143+
144+
// Sync back to first revision (local search keeps branch latest unchanged)
138145
Box::pin(sync::sync(
139146
repository.clone(),
140147
&write_token,
@@ -147,6 +154,14 @@ mod tests {
147154
.await
148155
.expect("Failed to sync back to first revision");
149156

157+
let latest_after_back = branch::load_latest(repository.clone(), branch_id)
158+
.await
159+
.expect("Failed to load branch latest after sync back");
160+
assert_eq!(
161+
latest_after_back, second_signature,
162+
"Local explicit sync should not move branch latest backwards"
163+
);
164+
150165
// Verify file added in first revision is still there
151166
assert!(
152167
fs::metadata(file_path.as_path())
@@ -159,18 +174,48 @@ mod tests {
159174
"File added in second revision was not removed as expected after sync back",
160175
);
161176

162-
// Sync forward to second revision
163-
Box::pin(sync::sync(
177+
// Simulate stale branch latest after an explicit remote sync bug
178+
branch::store_latest(
164179
repository.clone(),
165-
&write_token,
166-
SyncOptions {
167-
revision: Some(second_signature.to_string()),
168-
filter_mode: lore_revision::filter::FilterMode::Full,
180+
branch_id,
181+
first_signature,
182+
branch::BranchLatestStatus::Convergent,
183+
)
184+
.await
185+
.expect("Failed to seed stale branch latest");
186+
187+
let remote_execution = std::sync::Arc::new(ExecutionContext::new_client(
188+
LoreGlobalArgs {
189+
remote: 1,
169190
..Default::default()
170191
},
171-
))
172-
.await
173-
.expect("Failed to sync forward to second revision");
192+
EventDispatcher::no_dispatch(),
193+
));
194+
195+
// Sync forward to second revision with explicit remote search location
196+
LORE_CONTEXT
197+
.scope(
198+
remote_execution,
199+
Box::pin(sync::sync(
200+
repository.clone(),
201+
&write_token,
202+
SyncOptions {
203+
revision: Some(second_signature.to_string()),
204+
filter_mode: lore_revision::filter::FilterMode::Full,
205+
..Default::default()
206+
},
207+
)),
208+
)
209+
.await
210+
.expect("Failed to sync forward to second revision");
211+
212+
let latest_after_forward = branch::load_latest(repository.clone(), branch_id)
213+
.await
214+
.expect("Failed to load branch latest after sync forward");
215+
assert_eq!(
216+
latest_after_forward, second_signature,
217+
"Explicit remote sync should update branch latest pointer"
218+
);
174219

175220
// Verify file added in first revision is still there
176221
assert!(

0 commit comments

Comments
 (0)