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.
This commit is contained in:
Joe 2026-02-02 14:21:40 -06:00
parent d5522b2fef
commit d4ae0820bc

View file

@ -361,6 +361,9 @@ 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)
@ -372,12 +375,30 @@ fn refresh_git_index(project_dir: &Path) {
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;
}
}
}
}
} else {