Skip to content

Commit

Permalink
Ensure that builds within the cache aren't considered Git repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 20, 2024
1 parent 8df48f0 commit 59d2f3e
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,26 @@ impl Cache {

// Add the .gitignore.
let gitignore_path = root.join(".gitignore");
if !gitignore_path.exists() {
let mut file = fs::File::create(gitignore_path)?;
file.write_all(b"*")?;
match fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(gitignore_path)
{
Ok(mut file) => file.write_all(b"*")?,
Err(err) if err.kind() == io::ErrorKind::AlreadyExists => (),
Err(err) => return Err(err),
}

// Add a phony .git, if it doesn't exist, to ensure that the cache isn't considered to be
// part of a Git repository. (Some packages will include Git metadata (like a hash) in the
// built version if they're in a Git repository, but the cache should be viewed as an
// isolated store.)
let git_path = root.join(".git");
let _ = fs::OpenOptions::new()
.create(true)
.write(true)
.open(git_path);

fs::canonicalize(root)
}

Expand Down

0 comments on commit 59d2f3e

Please sign in to comment.