nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Git pre-commit/push hook

Open infinisil opened this issue 7 months ago • 9 comments

We should have this in Nixpkgs for https://github.com/NixOS/nixpkgs/pull/326407. Here are some notes for that:

  • For every push/commit, it should verify that changed and new files are formatted
    • For every commit is more useful because like that no extra commits will be necessary just to format
    • But for every push would also have advantages, see https://github.com/NixOS/nixpkgs/pull/322537#issuecomment-2214466166
    • Ideally this could also be together with a rewrite/rebase mode, kind of like https://github.com/grahamc/git-rebase-format/blob/master/git-rebase-format.sh (ref #159), which would allow users to rebase their PRs, maintaining the same commits, but formatting each of them
      • Probably something with git filter-branch would be much simpler than that script though
  • It should use the nixfmt version pinned in the shell.nix
  • It should install itself into .git/hooks automatically via shellHook (this is also how https://github.com/cachix/git-hooks.nix works)
  • Not a requirement, but ideally it would share as much with the GitHub Action workflow as possible. It's notably fairly easy to get another Git checkout of the base branch.

Ping @emilazy

infinisil avatar Jul 11 '24 22:07 infinisil