Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oppodelldog/git-commit-hook
automatically prepend branch name in git commit message, useful when working with feature/branches and a jira for example
https://github.com/oppodelldog/git-commit-hook
automation commit-hooks git git-flow goland jetbrains-ides jira phpstorm
Last synced: 5 days ago
JSON representation
automatically prepend branch name in git commit message, useful when working with feature/branches and a jira for example
- Host: GitHub
- URL: https://github.com/oppodelldog/git-commit-hook
- Owner: Oppodelldog
- License: mit
- Created: 2018-05-25T15:52:20.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-04-01T12:23:49.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T06:24:19.174Z (7 months ago)
- Topics: automation, commit-hooks, git, git-flow, goland, jetbrains-ides, jira, phpstorm
- Language: Go
- Homepage:
- Size: 73.2 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Go Report Card](https://goreportcard.com/badge/github.com/Oppodelldog/git-commit-hook)](https://goreportcard.com/report/github.com/Oppodelldog/git-commit-hook) [![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/Oppodelldog/git-commit-hook/master/LICENSE) [![Linux build](http://nulldog.de:12080/api/badges/Oppodelldog/git-commit-hook/status.svg)](http://nulldog.de:12080/Oppodelldog/git-commit-hook)
# git-commit-hook
> configureable git commit hook### 1. Install
Downlod the binary, put it into a folder of your $PATH (for example. /usr/local/bin).
Ensure your user has execution permissions on that file.
### 2. Configure
There are several places you can put the configuration.Create a config file named ```git-commit-hook.yaml```.
Create the configuration below your user folder:
**/home/*user*/.config/git-commit-hook**
```yaml
"project xyz":
# path to the git repository
path: "/home/nils/projects/xyz/.git"# define types of branch and a pattern to identify the type for the current branch you are working on
branch:
master: "^(origin\\/)*master"# define a commit message template per branch type, or as here for all (*) branch types
template:
"*": "{.BranchName}: {.CommitMessage}"# define validation rules per branch type
validation:
master:
"^.*(#\\d*)+.*$" : must have a ticket reference (eg. #267)
```Watch out the test [fixture](config/test-data.yaml) for full feature sample
### 3. Activate
Use the subcommand ```install``` to activate the commit-message-hook in your repository.## Sub-Commands
There are some useful subcommands which ease the use of the commit-message hook.### git-commit-hook install
Installs the commit-hook in the configured repositories.You need to specify either **-p** or **-a**.
* **-p** to install in the given repository (eg. **-p "project xyz"**)
* **-a** to install in all configured repositoriesIf there's already a commit-message-hook installed, you can overwrite by adding ```-f```.
### git-commit-hook uninstall
Uninstalls the commit-hook from the configured repositories.You need to specify either **-p** or **-a**.
* **-p** to uninstall from the given repository (eg. **-p "project xyz"**)
* **-a** to uninstall from all configured repositories### git-commit-hook diag
Gives an overview of the configuration and the installed commit hooks### git-commit-hook test
The test command is useful to test configuration and simulate a commit-situation.
You may input the following parameters:
* **-p** project name
* **-b** branch name
* **m** commit message**Sample:**
```shell
git-commit-hook test -m "short commit message" -b master -p testrepo
```in this case, validation will fail, since it's required to give a ticket/issue reference in the commit message.
```shell
testing configuration '/home/nils/.config/git-commit-hook/git-commit-hook.yaml':
project : testrepo
branch : master
commit message : short commit messagevalidation error for branch 'master'
at least expected one of the following to match
- must have a ticket reference (eg. #267)
```If you pass a valid commit message
```shell
git-commit-hook test -m "fix #121" -b master -p testrepo
```shows not validation errors, but shows the finally rendered message.
```shell
testing configuration '/home/nils/.config/git-commit-hook/git-commit-hook.yaml':
project : testrepo
branch : master
commit message : fix #121would generate the following commit message:
fix #121
```