From dddab62ea1785ca52117c8e5a8096a96b71b9fa2 Mon Sep 17 00:00:00 2001 From: Joe Date: Mon, 2 Feb 2026 14:24:54 -0600 Subject: [PATCH] Refactor git index refresh logic in syncback - Simplified the `refresh_git_index` function by removing the retry mechanism and directly handling the exit code of the `git update-index --refresh` command. Now, it logs a warning only if the command fails to execute, improving clarity and reducing unnecessary complexity. --- src/cli/syncback.rs | 48 +++++++++------------------------------------ 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/cli/syncback.rs b/src/cli/syncback.rs index 0c4a7dc4..b6ffea59 100644 --- a/src/cli/syncback.rs +++ b/src/cli/syncback.rs @@ -361,45 +361,15 @@ fn refresh_git_index(project_dir: &Path) { if is_git_repo { log::info!("Refreshing git index..."); - 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."); - 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; - } - } - } + // Exit code 1 is normal - it just means files were refreshed. + // We only warn if git itself fails to run. + match Command::new("git") + .args(["update-index", "--refresh", "-q"]) + .current_dir(project_dir) + .status() + { + Ok(_) => log::info!("Git index refreshed."), + Err(e) => log::warn!("Failed to run git update-index --refresh: {}", e), } } else { log::debug!("Not a git repository, skipping index refresh.");