Skip to content

Commit

Permalink
Handle a successfully-started-but-unsuccessful git rev-parse call
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Soltis authored and Greg Soltis committed May 16, 2023
1 parent 16d0bfa commit 16e80b3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion crates/turborepo-scm/src/package_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,20 @@ pub(crate) fn find_git_root(
.args(["rev-parse", "--show-cdup"])
.current_dir(turbo_root)
.output()?;
if !rev_parse.status.success() {
let stderr = String::from_utf8_lossy(&rev_parse.stderr);
return Err(Error::git_error(format!(
"git rev-parse --show-cdup error: {}",
stderr
)));
}
let root = String::from_utf8(rev_parse.stdout)?;
Ok(turbo_root.join_literal(root.trim_end()).clean())
}

#[cfg(test)]
mod tests {
use std::process::Command;
use std::{assert_matches::assert_matches, process::Command};

use super::*;

Expand Down Expand Up @@ -86,6 +93,14 @@ mod tests {
assert_eq!(result, link);
}

#[test]
fn test_no_git_root() {
let (_, tmp_root) = tmp_dir();
tmp_root.create_dir_all().unwrap();
let result = find_git_root(&tmp_root);
assert_matches!(result, Err(Error::Git(_, _)));
}

#[test]
fn test_get_package_deps() -> Result<(), Error> {
// Directory structure:
Expand Down

0 comments on commit 16e80b3

Please sign in to comment.