Skip to content

Commit

Permalink
Perform clone and checkout in separate steps
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Nov 23, 2024
1 parent c33d29a commit d729492
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/on_disk_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ impl Cache {
command
} else {
let mut command = Command::new("git");
// smoelius: The checkout is performed as a separate step so that errors that occur
// in it can be ignored.
command.args([
"clone",
"--depth=1",
"--no-checkout",
"--quiet",
url.as_str(),
&repo_dir.to_string_lossy(),
Expand All @@ -209,6 +212,8 @@ impl Cache {
let output = command
.output()
.with_context(|| format!("failed to run command: {command:?}"))?;
// smoelius: Perform checkout. As mentioned above, errors are ignored.
checkout(&repo_dir)?;
if output.status.success() {
return Ok((url.as_str().to_owned(), repo_dir));
}
Expand Down Expand Up @@ -395,3 +400,17 @@ fn repository_existence(repo_dir: &Path) -> Result<bool> {
)
})
}

fn checkout(repo_dir: &Path) -> Result<()> {
let mut command = Command::new("git");
command.args(["checkout", "--quiet"]);
command.current_dir(repo_dir);
let output = command
.output()
.with_context(|| format!("failed to run command: {command:?}"))?;
if !output.status.success() {
let error = String::from_utf8(output.stderr)?;
crate::warn!("failed to checkout `{}`: {}", repo_dir.display(), error);
}
Ok(())
}

0 comments on commit d729492

Please sign in to comment.