Feature/implement hooks #185

Open
wants to merge 24 commits into
from

Conversation

Projects
None yet
7 participants

Pull request for issue #171

petervanderdoes added some commits Dec 24, 2011

@petervanderdoes petervanderdoes Add directory setup to the git flow init process
git flow will fail when the directories are not setup in the git config.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
3f8934e
@petervanderdoes petervanderdoes Rename the Hooks directory variable.
Renamed so it won't be confused with the already present GITFLOW_DIR variable, which holds the dorectory info of where the gitflow scripts are located.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
3c2852f
@petervanderdoes petervanderdoes Implements do_hook function
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
dcf0c6d
@petervanderdoes petervanderdoes Add the pre and post hook calls.
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
3b63d1f
@petervanderdoes petervanderdoes Add some documentation to the do_hook function
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
46007c5
@petervanderdoes petervanderdoes Remove trailing whitespace
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
6ec1707
@petervanderdoes petervanderdoes Makes the feature more compliant with nvie comments in #171
Renames the called hooks to new proposed naming convention.
Removes the configurable configuration/hooks directory. All hooks are to be stored in .git/hooks

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
02200f0

Lots of whitespace drive-bys here, but other than that, 👍

@c00kiemon5ter c00kiemon5ter commented on an outdated diff Jan 2, 2012

gitflow-common
+ local prefix="$1"
+ local return_code=0
+
+ if [ -z $prefix ]; then
+ die "Hook implementation error - No prefix given"
+ fi
+ if [ $prefix != "pre" ] && [ $prefix != "post" ]; then
+ die "Hook implementation error - Bad Prefix"
+ fi
+
+ if [ -x ${GITFLOW_DIR_HOOKS}${prefix}-flow-${SUBCOMMAND}-${SUBACTION} ]; then
+ ${GITFLOW_DIR_HOOKS}${prefix}-flow-${SUBCOMMAND}-${SUBACTION}
+
+ return_code=$?
+
+ if [ $return_code -gt 0 ]; then
@c00kiemon5ter

c00kiemon5ter Jan 2, 2012

I think -ne would be better in place of -gt

use ?w=1 at the end of the url to see a cleaner diff

I know. I just fundamentally disagree with committing whitespace-only
changes to files in someone else's project ;)

petervanderdoes and others added some commits Dec 24, 2011

@petervanderdoes @nvie petervanderdoes Add directory setup to the git flow init process
git flow will fail when the directories are not setup in the git config.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
cbe180f
@petervanderdoes @nvie petervanderdoes Rename the Hooks directory variable.
Renamed so it won't be confused with the already present GITFLOW_DIR variable, which holds the dorectory info of where the gitflow scripts are located.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
e4e0e0c
@petervanderdoes @nvie petervanderdoes Implements do_hook function
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
178cecb
@petervanderdoes @nvie petervanderdoes Add the pre and post hook calls.
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
56ec32c
@petervanderdoes @nvie petervanderdoes Add some documentation to the do_hook function
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
c2fe6c7
@petervanderdoes @nvie petervanderdoes Remove trailing whitespace
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
7c03411
@petervanderdoes @nvie petervanderdoes Makes the feature more compliant with nvie comments in #171
Renames the called hooks to new proposed naming convention.
Removes the configurable configuration/hooks directory. All hooks are to be stored in .git/hooks

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
Signed-off-by: Vincent Driessen <vincent@3rdcloud.com>
e93a50b
@nvie Revert all whitespace changes. 31e637d
@nvie Refactor the code a bit.
It now has explicit pre and post functions to communicate the difference
in exit code handling.  Also, allow for passing in positional arguments
that make sense on a per-action basis.
203a793
@nvie Call the hooks explicitly on a per-action basis, with positional
arguments that are relevant for the action at hand.
359db20
@nvie Add some example hook scripts. 9283eae
Owner

nvie commented Jan 2, 2012

Take a look at this: develop...feature/implement-hooks

I've currently only implemented it for the feature actions, not yet for hotfix and release, but they will be trivial. What do you guys think? (The files inside the hooks/ directory serve as example scripts that you can use as a template when writing your own hook scripts.)

Why is there a different hook function for pre and post?

Shouldn't there be a message if the post script hook fails as well?

BTW apologies about the white space. My editor was setup to automatically remove eol white space.

Owner

nvie commented Jan 3, 2012

I think it's useful to display a message when the post-hook fails, but I also think there are some cases where errors should be tolerated (e.g. a best-effort "notification" message or something). This puts the post-hook script itself in control as to whether or not errors are acceptable.

I agree that the scripts, post and pre, are in control whether or not errors are acceptable. I think that notification of success or more descriptive failure message is also upon the scripts. In a pre script that means, if the error is acceptable, you exit with exit code 0 and git flow continues happily. In a post script there is no such option, git flow will always continue happily.

Looking at where the post_hooks are called from right now, an example where a die from the git flow script could be useful in a post hook would be in the git flow feature finish.
The hook is called before the finish cleanup is done. In the post script something might be determined where the merged branches shouldn't be deleted.

petervanderdoes added some commits Jan 6, 2012

@petervanderdoes petervanderdoes Adds pre/post hooks
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
07c40b0
@petervanderdoes petervanderdoes Add bare-bone hook scripts for feature and hotfix.
Bare bone pre and post cripts for the hooks of "git flow feature" and "git flow hotfix"

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
c488c4d
@petervanderdoes petervanderdoes Implements hooks for git flow release
Hooks added
Bare bone scripts for git flow release added
Fixes wrong post hook call for git flow hotfix publish

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
b5dd304

I believe I implemented all hooks as described in #171.
If somebody can take a look, I appreciate that.

booch commented Jun 12, 2012

👍

What else needs to happen to get this merged?

Not sure,

I decided to implement the feature on my own fork, including other features and bug fixes.
I recently released 1.0-avh, see the changelog for more details

baby-gnu commented Jul 4, 2012

Hello,

I tried to use this feature and wonder if it's not possible to run hooks from other places:

  • HOOKS_DIR: is .git/hooks
  • GITFLOW_USER_HOOKS_DIR: configurable with gitflow.hooks-dir.user
  • GITFLOW_SYSTEM_HOOKS_DIR: configurable with gitflow.hooks-dir.system

This will ease the share and updates of pre/post hooks and filters in a team, for example by distributing a new distribution package or managing them in a git repository itself.

Regards.

Update: Implemented in petervanderdoes/gitflow#1

Would love to see this merged. Anything else needed for that to happen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment