From d4ae0820bc54e36b51c631410c382d9a4091dc53 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 2 Feb 2026 14:21:40 -0600 Subject: [PATCH] Implement retry logic for git index refresh in syncback - Enhanced the `refresh_git_index` function to include a retry mechanism for the `git update-index --refresh` command, allowing for up to two attempts with a 500ms delay between retries in case of failure. This improves robustness in handling transient errors during the refresh process. --- src/cli/syncback.rs | 51 ++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 15 deletions(-) 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 {