Some useful hooks for git-flow (AVH Edition).
- Prevent direct commits to the master branch.
- Prevent merge marker commits.
- Automatically bump versions when starting a release or hotfix. Versions are generated, written to file and committed.
- Automatically specify tag messages.
Clone this repository somewhere on your disk.
git clone [email protected]:accessd/git-flow-hooks.git
Whenever your read /path/to/git-flow-hooks
, replace it with the actual path to your clone/working copy.
OS X doesn't support sort -V
, which is used to sort git tags by version number, which in turn is needed to correctly bump versions.
On OS X you can install coreutils (using MacPorts or Homebrew), after which gsort -V
can be used.
If it's located at /opt/local/bin/gsort
or /usr/local/bin/gsort
we will pick it up automatically.
Otherwise we fall back to /usr/bin/sort
.
Optionally you can use the configuration option VERSION_SORT
to point to a different command.
Initialize git-flow.
git flow init
It will ask you some questions, the last will be Hooks and filters directory?
, which you can answer with /path/to/git-flow-hooks
.
If you've already initialized git-flow, you can still set/change the path manually.
git config gitflow.path.hooks /path/to/git-flow-hooks
Simply pull any updates from origin.
cd /path/to/git-flow-hooks
git pull
That's it, all your repositories that have git-flow initialized and use /path/to/git-flow-hooks
as hooks and filters directory will be up-to-date.
This is completely optional!
Copy the file /path/to/git-flow-hooks/modules/git-flow-hooks-config.sh.dist
to /path/to/git-flow-hooks/git-flow-hooks-config.sh
(hooks directory) and change whatever you like.
Copy the file /path/to/git-flow-hooks/modules/git-flow-hooks-config.sh.dist
to .git/git-flow-hooks-config.sh
(repository root) and change whatever you like.
Any settings in the local configuration file will override settings in the global one. So remove settings you don't want to override.
git-flow (AVH Edition) has some useful configuration options too.
See its wiki for a complete list.
Or you can type git flow <command> [<subcommand>] --help
.
If git flow release start
and git flow hotfix start
are run without a version, the version will be bumped automatically.
Releases will be bumped at the minor level (1.2.3
becomes 1.3.0
), hotfixes at the patch level (1.2.3
becomes 1.2.4
).
The hooks will look at the git tags to find the version to bump.
If no tags are found, it looks for the version-file.
If that isn't found, it assumes the current version is 0.0.0
.
Alternatively you may use patch
, minor
and major
as version.
A bump of that level will take place.
If the commands are run with version, that version will be used (no bumping).
git-flow-hooks bumps the version in a commit with the message "Bump version to %version%".
If you want to use a different message, you can change it in the git-flow-hooks configuration.
If you want tag messages to be automated (you won't be bothered with your editor to specify it), use the following configuration options:
git config gitflow.hotfix.finish.message "Hotfix %tag%"
git config gitflow.release.finish.message "Release %tag%"
If you like, you can change the tag-placeholder (%tag%
in the example above) in the git-flow-hooks configuration.
git-flow-hooks is published under The MIT License, see the LICENSE file.
Note that these hooks are built for git-flow (AVH Edition) by Peter van der Does, which has its own licenses.
The scripts for preventing master and merge marker commits are based on git-hooks by Sitebase.