-
Notifications
You must be signed in to change notification settings - Fork 10
/
format-git-repo.sh
executable file
·22 lines (14 loc) · 1017 Bytes
/
format-git-repo.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/bash
# Helper script that formats all Nim files in a repository and commits the changes
set -eo pipefail
git diff --exit-code > /dev/null || { echo "Commit changes before doing a (potentially) large reformat!" ; exit 1 ; }
git ls-files | grep ".nim$" | xargs -n1 nph
! git diff --exit-code > /dev/null || { echo "This repository is already formatted" ; exit 0 ; }
git commit -am "Formatted with nph $(nph --version)" --author "nph <nph@example.com>"
echo "# Formatted with nph $(nph --version)" >> .git-blame-ignore-revs
echo "$(git rev-parse HEAD)" >> .git-blame-ignore-revs
git add .git-blame-ignore-revs
git commit -m "Add $(git rev-parse HEAD) to .git-blame-ignore-revs" --author "nph <nph@example.com>"
echo "The repo has been updated with two commits recording the reformatting and blame information."
echo "You can review the changes with 'git diff HEAD^^' before pushing to a public repository."
echo "If you don't want blame information, remove the last commit with 'git reset --hard HEAD^'."