Skip to content

Git templates containg hooks to add branch and optional host info at the beginning of commit messages

License

Notifications You must be signed in to change notification settings

bennyslbs/slbs-git-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SLBS Git Template

SLBS Git Template

This is an alternative git template folder, actually it only contains special hooks, but might change in the future.

GIT HOOKS

The hooks can contain different implementations.

Implementations

Which hooks implementation to use set the HOOKS environment variable. Eg. To select empty hooks, then: on the command line:

HOOKS=empty git ...

If HOOKS is undefined, then the default implementation is used.

empty

Contains no hooks - and will newer contain any hooks.

empty implementation is empty. It is for selecting No hooks at all.

default

The only hook this implementation contain is commit-msg and git-lfs related hooks (autogenerated).

default are for prefix first line with a commit message with the branch that the commit is made on.

Further an optional ID for the host the commit is created on can be included.

Add hostId (optional) and branch to the beginning of the first line of commit messages.

The id have this form: 'branch'[@host_id]: Where ‘branch’ is the name of the branch.

  • If ‘branch’ is ‘master’ only m is printed (no ”)
  • If no branch a - is printed (no ”)
  • Else the branch name in ” is printed

[@host_id]@host_id” is optional (included if GIT_HOOKS_HOST_ID is set) [] just shows that it is optional. The @ is prepended to the content in GIT_HOOKS_HOST_ID.

commit-msg

The commit-msg hook implements the above functionality.

prepare-commit-msg

The prepare-commit-msg calls commit-msg hook if it is a merge. This is done since commit-msg hook is not (always?) run during commit of merges.

Usage

Set GIT_HOOKS_ROOT

Set environment variable GIT_HOOKS_ROOT to the root of this package - this folder.

Optionally Set GIT_HOOKS_HOST_ID

Set environment variable GIT_HOOKS_HOST_ID if you want to include a host ID, e.g. hostname:

export GIT_HOOKS_HOST_ID=`hostname`

Use the hooks for new git repositories

Add the following code to ~/.gitconfig:

[init]
     templatedir = /path/to/slbs-git-template/template

Note: The templates does not include a description file, like normal templates does, this is to prevent overwriting repository description files during git init on existing repository.

The default content for .git/description is:

Unnamed repository; edit this file 'description' to name the repository.

Use the hooks for existing git repositories

Optionally disable the hooks (for single commands)

This is intended to be a switch to set for single commands where the hooks is not wanted, then set the variable HOOKS=empty (or any non-existing impl … but more implementations might come in the future.

HOOKS=empty git ...

License

License: GNU General Public License, version 2

See: LICENSE or https://www.gnu.org/licenses/gpl-2.0.html.

About

Git templates containg hooks to add branch and optional host info at the beginning of commit messages

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages