From 72d624ec95f00e0ecfccb1f37dabf52b9b270d7b Mon Sep 17 00:00:00 2001 From: Malin Freeborn Date: Sat, 6 Apr 2024 02:00:09 +0200 Subject: [PATCH] write git hooks --- data/git/hooks.md | 29 +++++++++++++++++++++++++++++ new.sh | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 data/git/hooks.md diff --git a/data/git/hooks.md b/data/git/hooks.md new file mode 100644 index 0000000..652b61c --- /dev/null +++ b/data/git/hooks.md @@ -0,0 +1,29 @@ +--- +title: "git hooks" +tags: [ "Documentation", "data", "git" ] +--- + +Check out the sample hooks: + +```bash +cd $GIT_REPO +ls .git/hooks +head .git/hooks/pre-commit.sample +``` + +Add a hook to check the shell scripts in `$GIT_REPO` before making a commit: + +```bash +echo '#!/bin/sh +shellcheck *.sh' > .git/hooks/commit-msg +chmod u+x .git/hooks/commit-msg +``` + +## Committing + +Your `git hooks` will not enter the repository, but you can commit them to a repository, then request others add these git hooks to their own branch, by putting a note in the project's `README.md`. + +```markdown +The project comes with recommended git hooks. +You can activate the hooks with `git config core.hooksPath hooks`. +``` diff --git a/new.sh b/new.sh index f9227bb..f9985a8 100755 --- a/new.sh +++ b/new.sh @@ -14,7 +14,7 @@ filePath="$category/$(echo $name | sed 's/ /_/g').md" tagsList="$(echo \"$category | sed 's#\/#", "#g')\"" -[ -e "$filePath" ] && $EDITOR $filePath && exit 0 +[ -e "$filePath" ] && $EDITOR "$filePath" && exit 0 echo "--- title: \"$name\"