-
Notifications
You must be signed in to change notification settings - Fork 1
chore(dev-loop): kill the slow iteration loop on echo-wesley-gen tests #383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,16 +64,41 @@ if command -v rustup >/dev/null 2>&1; then | |||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # 3) Format (auto-fix if opted in) | ||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||
| # Auto-stage protocol: when ECHO_AUTO_FMT is on and rustfmt/prettier rewrite | ||||||||||||||||||||||||||||||||||
| # files, the hook used to abort and force a manual restage-and-recommit cycle | ||||||||||||||||||||||||||||||||||
| # (paying cargo + lint costs twice). Instead, if the working tree was *clean* | ||||||||||||||||||||||||||||||||||
| # relative to the index before the formatter ran, the formatted output is | ||||||||||||||||||||||||||||||||||
| # safe to auto-add: every modified line came from the staged content, so we | ||||||||||||||||||||||||||||||||||
| # stage the result and continue. Partial staging (any unstaged changes | ||||||||||||||||||||||||||||||||||
| # present before the formatter) still aborts, because we can't tell whether | ||||||||||||||||||||||||||||||||||
| # the formatter touched staged hunks, unstaged hunks, or both. | ||||||||||||||||||||||||||||||||||
| _auto_fmt="${ECHO_AUTO_FMT:-1}" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Snapshot whether the working tree has unstaged changes BEFORE any | ||||||||||||||||||||||||||||||||||
| # auto-formatter runs. `git diff --quiet` exits 0 if clean, 1 if dirty. | ||||||||||||||||||||||||||||||||||
| if git diff --quiet; then | ||||||||||||||||||||||||||||||||||
| HAD_UNSTAGED_BEFORE_FMT=0 | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| HAD_UNSTAGED_BEFORE_FMT=1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| case "${_auto_fmt}" in | ||||||||||||||||||||||||||||||||||
| 1|true|TRUE|yes|YES|on|ON) | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: ECHO_AUTO_FMT=${_auto_fmt} → checking format" | ||||||||||||||||||||||||||||||||||
| if ! cargo fmt --all -- --check; then | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: running cargo fmt to apply changes" >&2 | ||||||||||||||||||||||||||||||||||
| cargo fmt --all || { echo "pre-commit: cargo fmt failed" >&2; exit 1; } | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: rustfmt updated files. Aborting commit to preserve index integrity (partial staging safe)." >&2 | ||||||||||||||||||||||||||||||||||
| echo "Hint: review changes, restage (e.g., 'git add -p' or 'git add -A'), then commit again." >&2 | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| if [[ "$HAD_UNSTAGED_BEFORE_FMT" -eq 0 ]]; then | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: rustfmt updated files; auto-staging (working tree was clean)." >&2 | ||||||||||||||||||||||||||||||||||
| git add -u || { echo "pre-commit: failed to re-stage rustfmt changes" >&2; exit 1; } | ||||||||||||||||||||||||||||||||||
| # Refresh STAGED so later steps see the post-fmt index. | ||||||||||||||||||||||||||||||||||
| STAGED=$(git diff --cached --name-only) | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: rustfmt updated files but you had unstaged changes; aborting to preserve partial-staging integrity." >&2 | ||||||||||||||||||||||||||||||||||
| echo "Hint: review changes, restage (e.g., 'git add -p' or 'git add -A'), then commit again." >&2 | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||
| 0|false|FALSE|no|NO|off|OFF) | ||||||||||||||||||||||||||||||||||
|
|
@@ -139,14 +164,27 @@ if [[ ${#MD_FILES[@]} -gt 0 ]] && command -v npx >/dev/null 2>&1; then | |||||||||||||||||||||||||||||||||
| : # Already formatted | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: running prettier on markdown files" >&2 | ||||||||||||||||||||||||||||||||||
| # Re-snapshot working-tree dirtiness for the markdown path specifically. | ||||||||||||||||||||||||||||||||||
| # The rustfmt step above may have auto-staged its own changes, so the | ||||||||||||||||||||||||||||||||||
| # earlier HAD_UNSTAGED_BEFORE_FMT value is stale by this point. | ||||||||||||||||||||||||||||||||||
| if git diff --quiet -- "${MD_FILES[@]}"; then | ||||||||||||||||||||||||||||||||||
| MD_HAD_UNSTAGED=0 | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| MD_HAD_UNSTAGED=1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+167
to
+174
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial | 💤 Low value Minor documentation nit: comment reasoning could be clearer. The comment claims
The real reason for the re-check is markdown-specific safety: verifying the exact files we're about to auto-stage are clean, independent of the earlier whole-tree snapshot. The logic itself is correct and defensive; just the comment's explanation is slightly off. 📝 Clearer comment wording- # Re-snapshot working-tree dirtiness for the markdown path specifically.
- # The rustfmt step above may have auto-staged its own changes, so the
- # earlier HAD_UNSTAGED_BEFORE_FMT value is stale by this point.
+ # Check working-tree dirtiness for the markdown files specifically.
+ # Even though we know the whole tree was clean before rustfmt, we verify
+ # these exact files are clean before auto-staging them (defensive check).
if git diff --quiet -- "${MD_FILES[@]}"; then📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| # Write changes; suppress stdout but preserve stderr for errors | ||||||||||||||||||||||||||||||||||
| if ! npx prettier --write "${MD_FILES[@]}" >/dev/null; then | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: prettier failed" >&2 | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: prettier updated markdown files. Aborting commit to preserve index integrity." >&2 | ||||||||||||||||||||||||||||||||||
| echo "Hint: review changes, restage (e.g., 'git add -p' or 'git add -A'), then commit again." >&2 | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| if [[ "$MD_HAD_UNSTAGED" -eq 0 ]]; then | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: prettier updated markdown files; auto-staging (markdown working tree was clean)." >&2 | ||||||||||||||||||||||||||||||||||
| git add -- "${MD_FILES[@]}" || { echo "pre-commit: failed to re-stage prettier changes" >&2; exit 1; } | ||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||
| echo "pre-commit: prettier updated markdown files but you had unstaged markdown edits; aborting to preserve partial-staging integrity." >&2 | ||||||||||||||||||||||||||||||||||
| echo "Hint: review changes, restage (e.g., 'git add -p' or 'git add -A'), then commit again." >&2 | ||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
cargo fmt --allrewrites any tracked Rust file outside the user's staged set while the worktree is otherwise clean, thisgit add -ustages every tracked formatter change, not just the files that were part of the commit. In that scenario the hook silently expands the commit with unrelated formatting edits; capture the originally staged paths and restage only those (or keep aborting when rustfmt touches other files).Useful? React with 👍 / 👎.