Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

simp4t7
Copy link
Contributor

@simp4t7 simp4t7 commented Sep 27, 2025

I think this is a fairly simple solution for #125654. The basic idea is just to stash local changes, run tidy, and then pop the changes back after Tidy runs for the pre-push git hook. It sort of got a bit more complicated with the error handling, but still seems like a reasonable solution.

A few things to note:

I opted to fail the whole check if git stash push -u fails instead of continuing to run Tidy on the unstashed changes. My thinking is git stash doesn't really fail easily so if it does something is probably pretty wrong and this way there's no inconsistency on what is being checked.

In general I think it's unlikely for git stash apply to fail because Tidy does not actually change files during its checks so there shouldn't be any risk of merge conflicts. If it does fail, it's a bit of a pain for the user, but handled and nothing is lost.

added error handling for git stash and apply

fix tidy err

abort if stash push fails

fix tidy errors... again
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 27, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

if [ -n "$(git status --porcelain)" ]; then
echo "Stashing local uncommitted changes before running Tidy."
# Stash uncommitted changes so that tidy only checks what you are going to push.
git stash push -u -q
Copy link
Member

Choose a reason for hiding this comment

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

I think that doing anything with untracked files might be a bit dangerous. I personally wouldn't want these scripts ever touching anything untracked by git.

@simp4t7
Copy link
Contributor Author

simp4t7 commented Sep 27, 2025

@Kobzol

So I think the best way to avoid stashing untracked files would probably be to have Tidy only run on tracked files. fmt already does this, so it sort of makes sense.

I did a little bit of digging anyways, and don't really think stashing untracked is extra dangerous though. Stash is basically all or nothing so on failure the working dir won't be affected. And once stashed it's still a commit under the hood so it's recoverable even if you explicitly drop the stash. But it is still stored locally, so there's always some risk I suppose. Just a note that --include-untracked will still respect the .gitignore.

Another option that could work well is throwing in a prompt asking if you want to stash changes before continuing. So if you're really worried you can back out and handle it manually if you prefer. I think it'd still have to include untracked unless you changed Tidy to ignore untracked first.

@bors
Copy link
Collaborator

bors commented Sep 28, 2025

☔ The latest upstream changes (presumably #147118) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants