Repository navigation
Accept Windows backslash paths in review --path, --files and --allow-path - #140
Open
mathuryashash wants to merge 1 commit into
Open
mathuryashash wants to merge 1 commit into
mathuryashash wants to merge 1 commit into
Conversation
…path PowerShell tab completion, VS Code's Copy Relative Path, Explorer and cmd write repository paths with backslashes. Git compares paths with '/', so on Windows --path and --files refused such a path as untracked and an --allow-path override silently never applied. Translate '\' to '/' once, as the clap value parser of the three flags, on Windows only: Git for Windows cannot check out a path containing '\', while elsewhere it is an ordinary file-name byte. Every existing refusal (., .., empty segments, directories, untracked paths) still applies to the translated value.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
On Windows,
proofline reviewrejects or silently ignores any repository path written with backslashes. That is the form PowerShell tab completion (.\src\main.rs), VS Code's Copy Relative Path (src\main.rs), Explorer and cmd all produce.proofline review --path src\main.rs"src\\main.rs" is not one exact repository-relative tracked file; no review was requestedproofline review --commit HEAD --files src\main.rs... is not a regular tracked file at commit ...proofline review --allow-path config\.env.envrefusal still fires and says to "pass --allow-path for that exact path"The
--allow-pathcase is the most confusing. The user passes the path they have, and the refusal message never says that only/works.Why: Git stores and compares paths with
/on every OS. The CLI hands the raw argument togit ls-files/ls-treeunder--literal-pathspecs(check_one_path,named_files) and compares it byte for byte with the diff's/paths (preflight::is_allowed), so a\never matches.Approach
git::repository_pathturns\into/on Windows only. It is applied once, as the clapvalue_parserof--path,--filesand--allow-path, so everything downstream sees Git's form and nothing else changes...\x,a\..\b,.\aanddir\are refused exactly as their/forms already are.\(it is a separator there, andcore.protectNTFSis on by default), so the change is lossless. On Linux and macOS\is a legal file-name byte, so values are kept as typed.#[allow], so the clap parser is a two-lineResultwrapper inlib.rsaround a plainfn(&str) -> String.I considered normalising inside
check_one_path,named_filesandpreflightseparately. That means three copies of the same fix, and the next path flag would miss it. I also consideredstd::path/canonicalize, but those resolve against the file system and follow symlinks, while the CLI is deliberately literal. I kept the existing.-segment refusal, so.\src\main.rsis refused just as./src/main.rsis today. I can drop that refusal if you'd rather accept PowerShell's completion form as-is.Verification
New tests:
tests/local_patch.rs::windows_backslash_paths_select_the_same_tracked_file(#[cfg(windows)], end-to-end against the existing fake server). It covers four cases:--path nestedile.txtuploads exactly thea/nested/file.txtdiff;.forms are refused before any HTTP request;--allow-path config oken.txtclears the secret refusal forconfig/token.txt;--files nestedile.txtsends"paths": ["nested/file.txt"].git::tests::repository_paths_use_git_separators_only_where_backslash_cannot_be_a_nameunit-tests both branches.Windows 11, toolchain 1.100.0, branch rebased onto current
main(d8c8103):mainwith"nested\file.txt" is not one exact repository-relative tracked file; no review was requested, and passes with this change;cargo test --locked --no-fail-fast: the same 12 tests fail onmainand on this branch (the pre-existing Windows-only failures tracked in CI: run cargo test and cargo clippy on the Windows job too #85).completions::the_bash_script_completes_subcommandsfails on both as well, depending on whichbash.exeWindows resolves; the generated bash completion script is byte-identical before and after this change. The two new tests pass;cargo fmt --checkis clean;cargo clippy --locked --lib --bins -- -D warningsis clean.Linux (Ubuntu under WSL, clean clone with this patch, run before the rebase; the rebase did not change the patch):
cargo test --test local_patchandcargo test --lib git::testspass, andcargo clippy --locked --all-targets -- -D warningsandcargo fmt --checkare clean.Proofline review
I installed Proofline on my fork and opened this change there first (mathuryashash#1). The review finished with no findings (a code-only review; the environment was not checked). Its walkthrough explains the change in two steps, the
--path/--filesselectors and then the--allow-pathoverride, which is how I would split it too, so I made no changes after it. Review run: https://proofline.sh/orgs/github/mathuryashash/reviews/pr/cli/1/runs/1Reproduce
In git-bash on Windows, with no token or network (every refusal happens before HTTP):