1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-04 10:25:01 +02:00
sap-jenkins-library/.hooks
Christopher Fenner 174d24460c
chore(go): add pre-commit hook (#1006)
* chore(go): add pre-commit hook
run go mod tidy
add description

* use bash

* adjust indentation

* fix code climate issue

* docs: clarify git hook usage description

* Update .hooks/README.md
2019-11-27 21:16:01 +01:00
..
pre-commit chore(go): add pre-commit hook (#1006) 2019-11-27 21:16:01 +01:00
README.md chore(go): add pre-commit hook (#1006) 2019-11-27 21:16:01 +01:00

Git Hooks

From Git docs:

Hooks are programs you can place in a hooks directory to trigger actions at certain points in git’s execution. Hooks that don’t have the executable bit set are ignored.

Usage

To use the hook, execute this command in the project root directory to link the script into the .git/hooks directory:

ln -s -f ../../.hooks/pre-commit ./.git/hooks/pre-commit

Make sure the file is executable:

chmod +x ./.hooks/pre-commit

Pre-Commit Hook

From Git docs:

This hook is invoked by git-commit, and can be bypassed with the --no-verify option. It takes no parameters, and is invoked before obtaining the proposed commit log message and making a commit. Exiting with a non-zero status from this script causes the git commit command to abort before creating a commit.

Content

Executes go mod tidy and stages go.mod & go.sum.

From Golang docs:

go mod tidy — Prune any no-longer-needed dependencies from go.mod and add any dependencies needed for other combinations of OS, architecture, and build tags (details).