Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(status): rudimentary support for filenames with spaces #1127

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

claytonrcarter
Copy link
Collaborator

@claytonrcarter claytonrcarter commented Nov 8, 2023

The regex in StatusEntry::try_from() was mistaken parsing status lines for files with spaces in such a way to discard the first word in the path name. This attempts to make that less likely by making the regex more specific, but I don't think it's really unavoidable without completely reworking this part of the code to be less flexible. eg if we parsed each of the 1/2/u statuses separately, then we could be more specific about how many fields we need to match/capture for each option.

I suspect that this issue was already rare, and that this fix will make it even moreso. Given that, I feel like a more robust/complex fix probably isn't warranted. With this fix, files like "r101 project.txt" or "Coffee notes.txt" will work, but "R101 project.txt" or "coffee notes.txt" ("R101" looks like a "change score", and "coffee" is a valid hex value.) (Edit: 🤦 coffee is not a "hex word"; c0ffee is, though.)

The options that come to mind to tighten this up further:

  • parse each 1/2/u status separately, making field counts and patterns more discrete
  • require a minimum number of chars in an object ID (on my Mac, the longest "hex word" in /usr/share/dict/words is 7 chars, so requiring at least 8 chars in an OID would eliminate "coffee"-style false positives)

git-branchless/tests/test_amend.rs Show resolved Hide resolved
git-branchless/tests/test_amend.rs Show resolved Hide resolved
git-branchless-lib/src/git/status.rs Outdated Show resolved Hide resolved
git-branchless-lib/tests/test_status.rs Show resolved Hide resolved
@claytonrcarter claytonrcarter marked this pull request as ready for review November 8, 2023 22:30
@claytonrcarter claytonrcarter force-pushed the crc/fix-status-spaces branch 2 times, most recently from 306e9b4 to 418f62e Compare November 10, 2023 12:31
Copy link
Owner

@arxanas arxanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

git-branchless/tests/test_amend.rs Outdated Show resolved Hide resolved
git-branchless-lib/src/git/status.rs Outdated Show resolved Hide resolved
git-branchless/tests/test_amend.rs Show resolved Hide resolved
The regex in `StatusEntry::try_from()` was mistaken parsing status lines for
files with spaces in such a way to discard the first word in the path name.
This attempts to make that less likely by making the regex more specific, but
I don't think it's really unavoidable without completely reworking this part
of the code to be less flexible. eg if we parsed each of the 1/2/u statuses
separately, then we could be more specific about how many fields we need to
match/capture for each option.

I suspect that this issue was already rare, and that this fix will make it even
moreso. Given that, I feel like a more robust/complex fix probably isn't
warranted. With this fix, files like "r101 project.txt" or "Coffee notes.txt"
will work, but "R101 project.txt" or "coffee notes.txt" ("R101" looks like a
"change score", and "coffee" is a valid hex value.)

The options that come to mind to tighten this up further:
- parse each 1/2/u status separately, making field counts and patterns more
  discrete
- require a minimum number of chars in an object ID (on my Mac, the longest
  "hex word" in /usr/share/dict/words is 7 chars, so requiring at least 8 chars
  in an OID would eliminate "coffee"-style false positives)
@claytonrcarter claytonrcarter enabled auto-merge (rebase) November 20, 2023 00:22
@claytonrcarter claytonrcarter merged commit 999bcf0 into arxanas:master Nov 20, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants