Skip to content

Commit

Permalink
better format script
Browse files Browse the repository at this point in the history
  • Loading branch information
arnetheduck committed Jan 8, 2024
1 parent fa9c745 commit 8c21825
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions format-git-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@

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)"

echo "Add the following two lines to .git-blame-ignore-revs to maintain git blame:"
echo "# Formatted with nph $(nph --version)"
echo "$(git rev-parse HEAD)"
echo "# Formatted with nph $(nph --version)" >> .git-blame-ignore-revs
echo "$(git rev-parse HEAD)" >> .git-blame-ignore-revs

git commit -am "Add $(git rev-parse HEAD) to .git-blame-ignore-revs"

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^'."

0 comments on commit 8c21825

Please sign in to comment.