Skip to content

et: Fix custom git diff prefix handling - #191108

Merged
cbracken merged 2 commits into
flutter:masterfrom
cbracken:fix-et-format
Aug 14, 2026
Merged

cbracken merged 2 commits into
flutter:masterfrom
cbracken:fix-et-format

Conversation

@cbracken

Copy link
Copy Markdown
Member

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.

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-assist bot 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.

`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.
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Aug 14, 2026
@cbracken
cbracken requested a review from goderbauer August 14, 2026 08:27
@github-actions github-actions Bot added the engine flutter/engine related. See also e: labels. label Aug 14, 2026
@cbracken
cbracken requested a review from jtmcdole August 14, 2026 08:27

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread engine/src/flutter/ci/bin/format.dart Resolved
Comment on lines +251 to +252
'--src-prefix=a/',
'--dst-prefix=b/',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No harm in using flags that were added in, check notes.... 2008. I wonder what problems that person ran in to 20 years ago.

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪙 The CodeFu LGTM Coin: Hard currency for soft commits.

  • Value: Pegged directly to 100 perfectly formatted Dart lines.
  • Utility: Redeemable for an emergency CI queue-jump or bypassing a non-blocking linter warning.
  • ⚠️ Warning: Subject to sudden hyperinflation if the engine roll breaks main.

codefu-coin

@jtmcdole jtmcdole added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 14, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Aug 14, 2026
@auto-submit

auto-submit Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

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.

@jtmcdole

Copy link
Copy Markdown
Member

Friends don't let friend's dashboard checks hang: re-running failed tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD engine flutter/engine related. See also e: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants