Coder Social home page Coder Social logo

git-flow-hooks's Introduction

git-flow-hooks

Some useful hooks for git-flow (AVH Edition).

What does it do?

  • 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.

Usage

Install

Clone this repository somewhere on your disk.

git clone [email protected]:jaspernbrouwer/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

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.

Activate

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

Prevention hooks

The hooks that prevent direct commits to the master branch, and prevent merge marker commits, are pre-commit hooks.

These only function if they're located in the .git/hooks directory of your working copy. In other words, after activating like described above, these hooks still won't kick in.

I see 2 options:

  1. In stead of activating like described above, remove the .git/hooks directory and make it a symbolic link (ln -s /path/to/git-flow-hooks .git/hooks).
  2. Create a symbolic link to the pre-commit file (ln -s /path/to/git-flow-hooks/pre-commit .git/hooks/pre-commit).

If you know a better way to use the pre-commit hooks, please let me know by opening an issue!

Update

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.

Configuration

This is completely optional!

Global

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.

Local

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

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.

Starting releases and hotfixes

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).

Bump messages

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.

Automatic tag messages

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.

Plugins

We want to create a plugin-like structure where users can add functionality in a more uniform way. Unfortunately, that would take some time and testing to implement.

While it's in progress, you can try to use the following forks:

License

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.

git-flow-hooks's People

Contributors

exaspark avatar gkorshunov avatar jaspernbrouwer avatar kitzberger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-flow-hooks's Issues

Version bump doesn't work

I use Ubuntu 15.04 with 'git flow 1.8.0 (AVH Edition)'.

README says:

If git flow release start and git flow hotfix start are run without a version, the version will be bumped automatically.

However when I try to start release without version number then I get this:
'fatal: 'release/.0.1' is not a valid branch name.
Fatal: Could not create release branch 'release/.0.1''

version file not passed to semverbump.sh

It seems as if the $VERSION_FILE variable is not properly passed from bump-version.sh to semverbump.sh. It is always null / empty.

The result is, that the current version is actually never read from the version file, if a custom one has been specified in git-flow-hooks-config.sh

can not clone. Permition denied

 git clone [email protected]:jaspernbrouwer/git-flow-hooks.git
Cloning into 'git-flow-hooks'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

So I change clone command:

git clone https://github.com/jaspernbrouwer/git-flow-hooks

Please update your DOC

[QUESTION] Set up only once

Is configuring these hooks something that everyone should do when cloning a repository where these hooks are to be used? Can I do this configuration only once?

Multiline tag message

Is it possible to create multiline tag messages? I'd like to introduce a new tag message variable to be replaced by a multiline text when finishing a release. Unfortunately all of the line breaks (\n) seem to get lost on the way from format-tag-message.sh to the actual tag message.

Maybe you can give me a push into the right direction ;-)

release start can't bump a auto version

on centos,

git clone [email protected]:jaspernbrouwer/git-flow-hooks.git

git flow init

git config gitflow.path.hooks git-flow-hooks/

git config gitflow.hotfix.finish.message "Hotfix %tag%"

git config gitflow.release.finish.message "Release %tag%"

git flow release start // error: Missing argument < version >

is any wrong in these steps ?

Allow global git-flow-hooks-config.sh

I want your hooks to be available in every local repository, existing or created in the future.
Generally, it's very easy to achieve this by globally setting gitflow.path.hooks.

What doesn't work is a global customization for all projects. For example, my version file always sits at version/version.txt. Right now, I need to create a git-flow-hooks-config.sh in each repository to perform this customization.

Prevent interactivity

Thank a lot for this, been looking for a more efficient way to deal with versioning for quite a while now!

I realize this is not very active, but I was wondering if there's a way to implement two small modifications:

1. Prevent Interactivity
While making a release or a feature it stills asks me for a commit message.
I've seen a question in SO that said I could make something like:

export GIT_MERGE_AUTOEDIT=no
git flow release finish -m 'Merge Message' release_branch_name
unset GIT_MERGE_AUTOEDIT

But I don't understand how to apply something like this inside the hooks, without the message and without the release name (using auto bump). Any ideas?

2. Automatically push commits on the master
After I finish a release, I'm taken to the master branch (using VSCode), and I can see that there are 2/3 commits to be pushed to origin. I was wondering if there would be way to automatically push after finishing a release/feature/hotfix.

Thanks a lot!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.