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

diff.noprefix=true causes missing filename in the diff: #21679

Open
x0f0 opened this issue Nov 21, 2024 · 1 comment
Open

diff.noprefix=true causes missing filename in the diff: #21679

x0f0 opened this issue Nov 21, 2024 · 1 comment
Labels
Milestone

Comments

@x0f0
Copy link

x0f0 commented Nov 21, 2024

Describe the bug
When running pants --changed-since=origin/main fix, I see:

parse_unified_diff
    raise ParseError(f"missing filename in the diff:\n{content}")

Pants version
2.23.0

OS
Linux.

Additional info
diff.noprefix=true in gitconfig, which seems to cause the issue.

@x0f0 x0f0 added the bug label Nov 21, 2024
@huonw
Copy link
Contributor

huonw commented Nov 22, 2024

Sorry for the trouble. I can reproduce. When I run with Pants 2.23.0, the full error output looks like:

12:13:14.91 [ERROR] missing filename in the diff:
diff --git path/to/file.py
index e9af958f0..f11ce88e0 100644
--- path/to/file.py
+++ path/to/file.py
@@ -15,0 +16 @@ ...
...

And indeed that matches the DiffParser.parse_unified_diff function:

if current_file is None:
raise ParseError(f"missing filename in the diff:\n{content}")

We should be more explicit in the prefixes in our git diff invocations: maybe this call should include "--src-prefix=a/", "--dst-prefix=b/" in the args list to sync with _filename_regex and be resilient to local configuration like this:

def _git_diff(self, *args: str) -> dict[str, tuple[Hunk, ...]]:
"""Run unsandboxed git diff command and parse the diff."""
return self._diff_parser.parse_unified_diff(self._git("diff", *args))

@x0f0 would you like to submit a fix? Thanks!

@huonw huonw added this to the 2.23.x milestone Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants