Skip to content

Commit

Permalink
fix(turborepo): Remove optional git locks (#8244)
Browse files Browse the repository at this point in the history
### Description

We weren't passing `--no-optional-locks` when calling git. This was
unnecessarily locking the index when we didn't need to. Now we pass the
flag.

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->
  • Loading branch information
NicholasLYang committed May 29, 2024
1 parent cc4e5d0 commit f580448
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
21 changes: 6 additions & 15 deletions crates/turborepo-scm/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl Git {

fn execute_git_command(&self, args: &[&str], pathspec: &str) -> Result<Vec<u8>, Error> {
let mut command = Command::new(self.bin.as_std_path());
command.args(args).current_dir(&self.root);
command
.args(args)
.current_dir(&self.root)
.env("GIT_OPTIONAL_LOCKS", "false");

if !pathspec.is_empty() {
command.arg("--").arg(pathspec);
Expand Down Expand Up @@ -181,21 +184,9 @@ impl Git {
file_path: &AbsoluteSystemPath,
) -> Result<Vec<u8>, Error> {
let anchored_file_path = self.root.anchor(file_path)?;
let mut command = Command::new(self.bin.as_std_path());
let command = command
.arg("show")
.arg(format!("{}:{}", from_commit, anchored_file_path.as_str()))
.current_dir(&self.root);
let arg = format!("{}:{}", from_commit, anchored_file_path.as_str());

let output = command.output()?;
if output.status.success() {
Ok(output.stdout)
} else {
Err(Error::Git(
String::from_utf8_lossy(&output.stderr).to_string(),
Backtrace::capture(),
))
}
self.execute_git_command(&["show", &arg], "")
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-scm/src/ls_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Git {
pub fn git_ls_tree(&self, root_path: &AbsoluteSystemPathBuf) -> Result<GitHashes, Error> {
let mut hashes = GitHashes::new();
let mut git = Command::new(self.bin.as_std_path())
.args(["ls-tree", "-r", "-z", "HEAD"])
.args(["ls-tree", "--no-optional-locks", "-r", "-z", "HEAD"])
.current_dir(root_path)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-scm/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl Git {
let mut git = Command::new(self.bin.as_std_path())
.args([
"status",
"--no-optional-locks",
"--untracked-files",
"--no-renames",
"-z",
Expand Down

0 comments on commit f580448

Please sign in to comment.