diff --git a/src/cli/syncback.rs b/src/cli/syncback.rs index b98cb62a..0c4a7dc4 100644 --- a/src/cli/syncback.rs +++ b/src/cli/syncback.rs @@ -361,23 +361,44 @@ fn refresh_git_index(project_dir: &Path) { if is_git_repo { log::info!("Refreshing git index..."); - let result = Command::new("git") - .args(["update-index", "--refresh"]) - .current_dir(project_dir) - .stdout(Stdio::null()) - .stderr(Stdio::null()) - .status(); + let mut attempts = 0; + loop { + attempts += 1; + let result = Command::new("git") + .args(["update-index", "--refresh"]) + .current_dir(project_dir) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); - match result { - Ok(status) => { - if status.success() { - log::info!("Git index refreshed."); - } else { - log::warn!("git update-index --refresh exited with: {}", status); + match result { + Ok(status) => { + if status.success() { + log::info!("Git index refreshed."); + break; + } else if attempts < 2 { + log::debug!( + "git update-index --refresh exited with: {}, retrying in 500ms...", + status + ); + std::thread::sleep(std::time::Duration::from_millis(500)); + } else { + log::warn!("git update-index --refresh exited with: {}", status); + break; + } + } + Err(e) => { + if attempts < 2 { + log::debug!( + "Failed to run git update-index --refresh: {}, retrying in 500ms...", + e + ); + std::thread::sleep(std::time::Duration::from_millis(500)); + } else { + log::warn!("Failed to run git update-index --refresh: {}", e); + break; + } } - } - Err(e) => { - log::warn!("Failed to run git update-index --refresh: {}", e); } } } else {