Repository navigation
et: Fix custom git diff prefix handling - #191108
Conversation
`et` performs formatting by diffing the repo file against the output of the formatter for that file, which it passes to stdin (`-`). This results in `git diff` outputting the "to" path as `-`. `et` then tries to rewrite that `-` to the repo path. For users with certain git settings such as `diff.mnemonicPrefix` or `diff.noprefix` the diff path prefixes emitted in the two-line ---/+++ file pair will differ from the default `a/` and `b/`, which the existing `et format` code assumes. The end result is a (silent) failure to rewrite the "to" path, with the result that when we apply the diff, the file is rewritten to a file named `-` at the root of the repo. We now explicitly pass git diff `--src-prefix` and `--dst-prefix` flags, which override git diff settings such as `diff.mnemonicPrefix`, `diff.noprefix`, `diff.srcPrefix` and `diff.dstPrefix`. I've extracted the diff job construction into a method that we reuse where needed and added some paranoid error checking to ensure we actually rewrite the path correctly.
There was a problem hiding this comment.
Code Review
This pull request refactors the format checkers to use a centralized createDiffJob helper, ensuring consistent git diff prefixes, and adds a safeguard in applyPatch to prevent writing files to the repository root when patches target stdin. It also introduces tests to verify formatting behavior under custom git prefix configurations. The review feedback suggests updating the stdin patch target regular expression to support CRLF line endings on Windows and asserting on the exit code of the formatter process in the new tests to avoid silent failures.
| '--src-prefix=a/', | ||
| '--dst-prefix=b/', |
There was a problem hiding this comment.
No harm in using flags that were added in, check notes.... 2008. I wonder what problems that person ran in to 20 years ago.
|
autosubmit label was removed for flutter/flutter/191108, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
|
Friends don't let friend's dashboard checks hang: re-running failed tests. |

etperforms formatting by diffing the repo file against the output of the formatter for that file, which it passes to stdin (-). This results ingit diffoutputting the "to" path as-.etthen tries to rewrite that-to the repo path.For users with certain git settings such as
diff.mnemonicPrefixordiff.noprefixthe diff path prefixes emitted in the two-line ---/+++ file pair will differ from the defaulta/andb/, which the existinget formatcode assumes. The end result is a (silent) failure to rewrite the "to" path, with the result that when we apply the diff, the file is rewritten to a file named-at the root of the repo.We now explicitly pass git diff
--src-prefixand--dst-prefixflags, which override git diff settings such asdiff.mnemonicPrefix,diff.noprefix,diff.srcPrefixanddiff.dstPrefix.I've extracted the diff job construction into a method that we reuse where needed and added some paranoid error checking to ensure we actually rewrite the path correctly.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.