21 lines
612 B
Bash
Executable File
21 lines
612 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Auto-format the tree with `nix fmt` (nixfmt-tree) and re-stage any files
|
|
# that were already staged for this commit so the commit picks up the
|
|
# formatted versions.
|
|
#
|
|
# Caveat: if you had partially-staged a file (some hunks staged, others not),
|
|
# re-staging here will sweep up the unstaged hunks too. Run `nix fmt` and
|
|
# re-stage by hand before committing if that matters.
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
mapfile -t staged < <(git diff --cached --name-only --diff-filter=ACM)
|
|
|
|
nix fmt -- --quiet
|
|
|
|
if [ "${#staged[@]}" -gt 0 ]; then
|
|
git add -- "${staged[@]}"
|
|
fi
|