Skip to content

Commit

Permalink
fix(Turborepo): Handle spaces in path names in git status (#7197)
Browse files Browse the repository at this point in the history
### Description

 - Don't stop `git status` parsing when encountering a space

### Testing Instructions

 - Added a unit test for `git status` testing
- Added an integration test for a dry run with an added file with a
space in the path name

Closes TURBO-2209

---------

Co-authored-by: Greg Soltis <Greg Soltis>
  • Loading branch information
Greg Soltis committed Jan 31, 2024
1 parent 7351651 commit 14f5207
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/turborepo-scm/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn nom_parse_status(i: &[u8]) -> nom::IResult<&[u8], StatusEntry<'_>> {
let (i, x) = nom::bytes::complete::take(1usize)(i)?;
let (i, y) = nom::bytes::complete::take(1usize)(i)?;
let (i, _) = nom::character::complete::space1(i)?;
let (i, filename) = nom::bytes::complete::is_not(" \0")(i)?;
let (i, filename) = nom::bytes::complete::is_not("\0")(i)?;
// We explicitly support a missing terminator
let (i, _) = nom::combinator::opt(nom::bytes::complete::tag(&[b'\0']))(i)?;
Ok((
Expand Down Expand Up @@ -125,6 +125,11 @@ mod tests {
),
("M package.json\0", "", ("package.json", false)),
("A some-pkg/some-file\0", "some-pkg", ("some-file", false)),
(
"M some-pkg/file with spaces\0",
"some-pkg",
("file with spaces", false),
),
];
for (input, prefix, (expected_filename, expect_delete)) in tests {
let prefix = RelativeUnixPathBuf::new(*prefix).unwrap();
Expand Down
12 changes: 12 additions & 0 deletions turborepo-tests/integration/tests/run/path-with-spaces.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Setup
$ . ${TESTDIR}/../../../helpers/setup_integration_test.sh

Force git status to show a file with spaces in the name
$ echo "new file" > packages/util/with\ spaces.txt

Verify we have a file with spaces in the name
$ git status | grep -q "with spaces"

Do a dry run to verify we can hash it
$ ${TURBO} run build --dry -F util | grep "Inputs Files Considered"
Inputs Files Considered = 2

0 comments on commit 14f5207

Please sign in to comment.