1.9 KiB
git-hooks
How it works
Git hooks adds prepare-commit-msg hook which is executed before committing message.
Hook script will take current branch name and parse issue ticket name/number from it. If found, ticket will be prepend to commit message, and link to jira ticket will be added at the end.
For example, if current branch is CLOUD-12345-some-important-branch and we add commit:
git commit -m "some important message"
resulting commit message will be:
git log
commit 963dca96dd658a7df590c8b27b45d7f7536f9c1d (HEAD -> CLOUD-12345-some-important-branch)
Author: Eden Kirin <eden@ekirin.com>
Date: Fri Sep 1 09:57:54 2023 +0200
CLOUD-12345: some important message
https://smartvending.atlassian.net/browse/CLOUD-12345
Branch CI/CD prefix such as feature/ will be handled correctly. If current branch is feature/CLOUD-12345-some-important-branch and we add commit:
git commit -m "some important message"
resulting commit message will be:
git log
commit 963dca96dd658a7df590c8b27b45d7f7536f9c1d (HEAD -> feature/CLOUD-12345-some-important-branch)
Author: Eden Kirin <eden@ekirin.com>
Date: Fri Sep 1 09:57:54 2023 +0200
CLOUD-12345: some important message
https://smartvending.atlassian.net/browse/CLOUD-12345
Installation
- Clone repository
git clone https://gitea.ekirin.com/Intis/git-hooks.git
Use in single repository
-
Copy
intis-hooksdirectory content toyour-repo-dir/.git/hooksdirectory. -
Make sure
prepare-commit-msgis executable. If not, make it:chmod +x prepare-commit-msg.
Use globally, as default hooks
-
Create
~/.git-templates -
Run the command:
git config --global init.templateDir '~/.git-templates'
-
Copy
intis-hooksdirectory content to~/.git-templates/hooks -
Reinitialize existing git repos you wish to use this in with:
git init -
Rename
your-repo-dir/.git/intis-hookstoyour-repo-dir/.git/hooks