diff --git a/README.md b/README.md index f964869..d243972 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,19 @@ gdscript-formatter --check path/to/file.gd To see other possible options, run `gdscript-formatter` without any arguments. +## Git pre-commit hook + +You can run the `gdscript-formatter` automatically on staged `.gd` prior to each commit. This repository includes a pre-commit hook you can copy into your project. + +From the root of your project, run: + +```sh +cp path/to/GDScript-formatter/hooks/pre-commit .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit +``` + +This copies the hook into `.git/hooks/`, where Git looks for hooks to run automatically. Git will now run the formatter on your staged `.gd` files before every commit. + ## Linting GDScript files The formatter also includes a linter that checks for style and convention issues according to the official GDScript style guide. diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..499c04e --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +staged=$(git diff --cached --name-only --diff-filter=ACM | grep '\.gd$') +[ -z "$staged" ] && exit 0 +echo "$staged" | xargs gdscript-formatter +git add $staged