(cwd: &Path, args: &[&str])
| 92 | } |
| 93 | |
| 94 | fn run_git(cwd: &Path, args: &[&str]) { |
| 95 | assert!(cwd.is_dir(), "git cwd {cwd:?} should exist"); |
| 96 | let git = git_program(); |
| 97 | let mut last_err: Option<std::io::Error> = None; |
| 98 | let mut output = None; |
| 99 | for attempt in 0..5 { |
| 100 | match std::process::Command::new(&git) |
| 101 | .args(args) |
| 102 | .current_dir(cwd) |
| 103 | .output() |
| 104 | { |
| 105 | Ok(out) => { |
| 106 | output = Some(out); |
| 107 | break; |
| 108 | } |
| 109 | Err(e) if e.kind() == std::io::ErrorKind::NotFound && attempt < 4 => { |
| 110 | last_err = Some(e); |
| 111 | std::thread::sleep(std::time::Duration::from_millis(20 * (attempt + 1))); |
| 112 | } |
| 113 | Err(e) => panic!("git {args:?} should run (program {git:?}): {e}"), |
| 114 | } |
| 115 | } |
| 116 | let output = |
| 117 | output.unwrap_or_else(|| panic!("git {args:?} should run after retries: {last_err:?}")); |
| 118 | assert!( |
| 119 | output.status.success(), |
| 120 | "git {:?} failed\nstdout:\n{}\nstderr:\n{}", |
| 121 | args, |
| 122 | String::from_utf8_lossy(&output.stdout), |
| 123 | String::from_utf8_lossy(&output.stderr) |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | #[cfg(windows)] |
| 128 | fn git_test_root(path: &Path) -> PathBuf { |
no test coverage detected