Stream: rustdoc

Topic: git pre-push hook


view this post on Zulip Noah Lev (Jul 26 2021 at 21:18):

Just mentioning that if you forget to run x fmt before pushing up your changes, you may find it useful to add a git pre-push hook that will run x fmt --check. To do so, add an executable file called pre-push to .git/hooks in your rust-lang/rust clone(s) with this content:

x fmt --check

(You'll have to install the in-tree src/tools/x tool for this to work, which is very useful by itself too.)

view this post on Zulip Noah Lev (Jul 26 2021 at 21:19):

The one downside is that pushes will take a bit longer (5 seconds longer, on my machine), but it may save time if you otherwise end up having to format and repush.

view this post on Zulip Léo Lanteri Thauvin (Jul 26 2021 at 22:45):

Or you can run a full tidy

view this post on Zulip Noah Lev (Jul 26 2021 at 23:53):

Léo Lanteri Thauvin said:

Or you can run a full tidy

True, but that would take longer, and in my experience, most of the time the formatting is the only part that needs to be fixed.

view this post on Zulip GuillaumeGomez (Jul 27 2021 at 08:19):

Please don't add git hooks. Especially on the rust compiler...

view this post on Zulip Léo Lanteri Thauvin (Jul 27 2021 at 09:03):

Noah Lev said:

The one downside is that pushes will take a bit longer (5 seconds longer, on my machine), but it may save time if you otherwise end up having to format and repush.

Personally, I usually have my editor format files on save, so when I know that everything is already formatted I run git with --no-verify

view this post on Zulip Joshua Nelson (Jul 27 2021 at 11:34):

@GuillaumeGomez you can configure hooks for yourself without adding them for everyone, I think that's what @Noah Lev is suggesting. x.py setup actually suggests installing a git hook but I suspect most of the people on the team added a config.toml before it started doing that and won't have seen the prompt.

view this post on Zulip GuillaumeGomez (Jul 27 2021 at 11:42):

Phew. I feel relieved

view this post on Zulip Noah Lev (Jul 27 2021 at 21:21):

Yeah, AIUI git hooks are fully local-only :)


Last updated: Oct 11 2021 at 22:34 UTC