Update a local git repository to the newest state. Resets any local changes in case in each repository beforehand to prevent any conflicts.
(repo: &str, target_dir: &Path)
| 196 | /// Update a local git repository to the newest state. |
| 197 | /// Resets any local changes in case in each repository beforehand to prevent any conflicts. |
| 198 | fn update_repo(repo: &str, target_dir: &Path) -> Result<(), Error> { |
| 199 | // Reset any possible local changes. |
| 200 | let output = Command::new("git") |
| 201 | .current_dir(target_dir) |
| 202 | .args(vec!["reset", "--hard"]) |
| 203 | .output() |
| 204 | .map_err(|source| Error::Io { |
| 205 | context: format!("resetting the package source repository \"{repo}\""), |
| 206 | source, |
| 207 | })?; |
| 208 | |
| 209 | ensure_success( |
| 210 | &output, |
| 211 | format!("Resetting the package source repository \"{repo}\""), |
| 212 | )?; |
| 213 | |
| 214 | let output = &Command::new("git") |
| 215 | .current_dir(target_dir) |
| 216 | .args(["pull", "--force"]) |
| 217 | .output() |
| 218 | .map_err(|source| Error::Io { |
| 219 | context: format!("pulling the package source repository \"{repo}\""), |
| 220 | source, |
| 221 | })?; |
| 222 | |
| 223 | ensure_success( |
| 224 | output, |
| 225 | format!("Pulling the package source repository \"{repo}\""), |
| 226 | ) |
| 227 | } |
| 228 | |
| 229 | /// Clone a git repository into a target directory. |
| 230 | fn clone_repo(mut repo: String, target_dir: &Path) -> Result<(), Error> { |
no test coverage detected