Skip to content

Accept Windows backslash paths in review --path, --files and --allow-path - #140

Open
mathuryashash wants to merge 1 commit into
prooflinedev:mainfrom
mathuryashash:fix/windows-backslash-paths
Open

mathuryashash wants to merge 1 commit into
prooflinedev:mainfrom
mathuryashash:fix/windows-backslash-paths

Conversation

@mathuryashash

Copy link
Copy Markdown

The problem

On Windows, proofline review rejects 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.

command (Windows) today
proofline review --path src\main.rs "src\\main.rs" is not one exact repository-relative tracked file; no review was requested
proofline review --commit HEAD --files src\main.rs ... is not a regular tracked file at commit ...
proofline review --allow-path config\.env the override silently does nothing; the .env refusal still fires and says to "pass --allow-path for that exact path"

The --allow-path case 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 to git ls-files / ls-tree under --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_path turns \ into / on Windows only. It is applied once, as the clap value_parser of --path, --files and --allow-path, so everything downstream sees Git's form and nothing else changes.
  • It translates and does not loosen anything. Every existing check runs on the normalised value: ..\x, a\..\b, .\a and dir\ are refused exactly as their / forms already are.
  • Why only on Windows: Git for Windows can't check out a path containing \ (it is a separator there, and core.protectNTFS is on by default), so the change is lossless. On Linux and macOS \ is a legal file-name byte, so values are kept as typed.
  • The crate denies #[allow], so the clap parser is a two-line Result wrapper in lib.rs around a plain fn(&str) -> String.

I considered normalising inside check_one_path, named_files and preflight separately. That means three copies of the same fix, and the next path flag would miss it. I also considered std::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.rs is refused just as ./src/main.rs is 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 nested ile.txt uploads exactly the a/nested/file.txt diff;
    • five backslash traversal, directory and . forms are refused before any HTTP request;
    • --allow-path config oken.txt clears the secret refusal for config/token.txt;
    • --files nested ile.txt sends "paths": ["nested/file.txt"].
  • git::tests::repository_paths_use_git_separators_only_where_backslash_cannot_be_a_name unit-tests both branches.

Windows 11, toolchain 1.100.0, branch rebased onto current main (d8c8103):

  • the new end-to-end test fails on main with "nested\file.txt" is not one exact repository-relative tracked file; no review was requested, and passes with this change;
  • full cargo test --locked --no-fail-fast: the same 12 tests fail on main and 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_subcommands fails on both as well, depending on which bash.exe Windows resolves; the generated bash completion script is byte-identical before and after this change. The two new tests pass;
  • cargo fmt --check is clean; cargo clippy --locked --lib --bins -- -D warnings is 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_patch and cargo test --lib git::tests pass, and cargo clippy --locked --all-targets -- -D warnings and cargo fmt --check are 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/--files selectors and then the --allow-path override, 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/1

Reproduce

In git-bash on Windows, with no token or network (every refusal happens before HTTP):

git init -q demo && cd demo && mkdir src && echo 'fn main() {}' > src/main.rs
git add . && git commit -qm init
git update-ref refs/remotes/origin/main HEAD && git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
echo '// changed' >> src/main.rs
export PROOFLINE_TOKEN=x PROOFLINE_ORGANIZATION_ID=00000000-0000-4000-8000-000000000001 PROOFLINE_NO_UPDATE_CHECK=1
proofline --base-url http://127.0.0.1:9 review --repo acme/web --path 'src\main.rs' --no-wait
# before: "src\\main.rs" is not one exact repository-relative tracked file
# after:  gets past the path check and fails to connect to 127.0.0.1:9

…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

No deployments
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.

1 participant