From 2f778215dfa66e08bd30f88b40118384cc929d57 Mon Sep 17 00:00:00 2001 From: arnaudgolfouse Date: Mon, 29 Jan 2024 17:19:17 +0100 Subject: [PATCH] change the commit hook strategy --- .pre-commit-hooks.yaml | 8 -------- README.md | 32 +++++++++++--------------------- 2 files changed, 11 insertions(+), 29 deletions(-) delete mode 100644 .pre-commit-hooks.yaml diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml deleted file mode 100644 index 492b543..0000000 --- a/.pre-commit-hooks.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -- id: typstfmt - name: typstfmt - description: > - format typst - entry: typstfmt - language: rust - files: \.typ$ diff --git a/README.md b/README.md index ab3672d..b314afb 100644 --- a/README.md +++ b/README.md @@ -54,33 +54,23 @@ cargo install --git https://github.com/astrale-sharp/typstfmt.git ## Setting up a pre-commit hook -You can set up a git [hook](https://pre-commit.com). - -Every `git commit`, will then format automatically every .typ file before -committing. - -run: +Optionally, you can setup a git hook to format your files at each commit: ```sh -echo "\ -repos: - - repo: https://github.com/astrale-sharp/typstfmt - rev: 1c414de - hooks: - - id: typstfmt -" > .pre-commit-config.yaml -``` +echo "set -e -to add a configured `.pre-commit-config.yaml` file. +for f in \$(git ls-files --full-name -- '*.typ') ; do + typstfmt --check \$f --verbose +done" > .git/hooks/pre-commit -You should then run: - -```sh -pre-commit install -pre-commit autoupdate +chmod +x .git/hooks/pre-commit ``` -And your set up is done! +Now if you try to commit unformatted files, they will be caught and the commit will fail, telling you which file should be fixed. + +> Notes: +> - You should probably avoid doing this at the moment, as typstfmt is not quite stable yet +> - Be careful if you have another commit hook setup, as the command above will replace it entirely! # Contributing