From 7620dace6efbff0bf82eb8f49120d1ca31479c10 Mon Sep 17 00:00:00 2001 From: Derek Greene Date: Sat, 11 Apr 2026 17:03:46 -0700 Subject: [PATCH 1/2] :sparkles: Add pre-commit hook --- .pre-commit-hooks.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml new file mode 100644 index 0000000..069056b --- /dev/null +++ b/.pre-commit-hooks.yaml @@ -0,0 +1,6 @@ +- id: gdscript-formatter + name: GDScript Formatter + description: Format GDScript files using gdscript-formatter + entry: gdscript-formatter + language: system + files: \.gd$ From f2b532ce5f9deca96c2df4d1f8764e6586c3ce94 Mon Sep 17 00:00:00 2001 From: Derek Greene Date: Mon, 13 Apr 2026 19:33:48 -0700 Subject: [PATCH 2/2] :recycle: Refactor niche hook in favor of standard git hook --- .pre-commit-hooks.yaml | 6 ------ README.md | 13 +++++++++++++ hooks/pre-commit | 5 +++++ 3 files changed, 18 insertions(+), 6 deletions(-) delete mode 100644 .pre-commit-hooks.yaml create mode 100755 hooks/pre-commit diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 069056b..0000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- id: gdscript-formatter - name: GDScript Formatter - description: Format GDScript files using gdscript-formatter - entry: gdscript-formatter - language: system - files: \.gd$ 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