noosphere_cli/native/commands/sphere/
sync.rs1use crate::native::{content::Content, workspace::Workspace};
2use anyhow::{anyhow, Result};
3use noosphere_core::context::{SphereSync, SyncExtent, SyncRecovery};
4
5pub async fn sync(auto_retry: u32, render_depth: Option<u32>, workspace: &Workspace) -> Result<()> {
10 workspace.ensure_sphere_initialized()?;
11
12 match Content::read_changes(workspace).await? {
13 Some((_, content_changes, _)) if !content_changes.is_empty() => {
14 return Err(anyhow!(
15 "You have unsaved local changes; save or revert them before syncing!"
16 ));
17 }
18 _ => (),
19 };
20
21 {
22 let mut context = workspace.sphere_context().await?;
23 context
24 .sync_with_options(SyncExtent::FetchAndPush, SyncRecovery::Retry(auto_retry))
25 .await?;
26 }
27
28 info!("Sync complete, rendering updated workspace...");
29
30 workspace.render(render_depth, false).await?;
31
32 info!("Done!");
33
34 Ok(())
35}