Skip to content

Read a type change as the two sections Git prints - #122

Open
devhimanshuhc wants to merge 1 commit into
prooflinedev:mainfrom
devhimanshuhc:fix/type-change-local-patch
Open

devhimanshuhc wants to merge 1 commit into
prooflinedev:mainfrom
devhimanshuhc:fix/type-change-local-patch

Conversation

@devhimanshuhc

Copy link
Copy Markdown

Problem

When a tracked file changes type, every local review of the change fails with a message about the CLI's internals. Examples are a file replaced by a symbolic link, a symbolic link replaced by a file, or either replaced by a submodule:

proofline: could not read the local patch's Git path metadata; no review was requested

This hits:

  • proofline review, with or without --staged, --include-untracked or --path;
  • the pre-commit hook;
  • the pre-push hook, which shares diff().

With onIncomplete=block, the hooks block the commit or push. Nothing tells the person that the symlink is the cause.

Cause

diff_paths reads git diff --raw -z --patch and records one PatchPaths entry per raw record, treating status T like M. Git prints a type change as two patch sections, a deletion and then a creation of the same path:

:100644 120000 … T	linked.txt
diff --git a/linked.txt b/linked.txt
deleted file mode 100644
…
diff --git a/linked.txt b/linked.txt
new file mode 120000
…

diff() then compares 1 path entry with 2 diff --git lines and returns GitError::InvalidDiff.

Change

diff_paths records a type change as a deletion followed by a creation, in Git's order. The path metadata then matches the sections, and preflight::check, which pairs each section with its path in order, reads removed lines against the old file and added lines against the new one. Mode-only changes such as 644 to 755 are M, not T, and are unaffected.

The public contract says the server refuses symbolic links and submodules in a patch. This change does not make them reviewable. It makes the CLI do what diff() already intends for gitlinks ("stays in the patch for the server to refuse"): send the patch and print the server's actual reason, instead of failing locally with an error that points at the CLI.

Verification

  • New tests in tests/local_patch.rs (Unix-only, since they create symlinks). Both fail on unmodified main with the metadata error and pass with this change:
    • a_file_replaced_by_a_symlink_uploads_its_two_sections_for_the_server: with and without --path, one upload with both diff --git a/linked.txt b/linked.txt sections (deleted file mode 100644, new file mode 120000).
    • a_secret_in_a_file_replaced_by_a_symlink_is_still_refused: secret-shaped content in the new side of a type change is still refused by the local preflight, naming the path and making no HTTP request.
  • cargo fmt --check and cargo clippy --locked --all-targets -- -D warnings are clean. cargo test --locked --no-fail-fast passes everything except unattended_registration_preserves_settings_and_uses_the_installed_binary, which fails the same way on unmodified main on macOS (unattended_registration_preserves_settings_and_uses_the_installed_binary fails on macOS (/var vs /private/var) #112).

Git prints a type change, such as a file replaced by a symbolic link, as
a deletion and a creation of the same path, but diff_paths recorded one
entry for it. The section count then disagreed with the path metadata,
so a local review and the commit and push hooks failed with "could not
read the local patch's Git path metadata" instead of sending the patch
for the server to judge. Record a deletion and a creation, in Git's
order, so preflight reads each section against its own path.

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