Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/implement version filter #186

Open
wants to merge 4 commits into from

1 participant

@petervanderdoes

Issue #129 asks to "add version number auto-increment support". Instead of having users to adhere to a given scheme I wrote a filter hook for the following commands:
git flow release start
git flow hotfix start

Explanation of the filter implementation.

  • A universal function is created called run_filter_hook
  • Naming conventions of the filter scripts filter-flow-{command} For example filter-flow-hotfix-start-version
  • The filter hook function is called with the 1st parameter being the {command} and the 2nd parameter being the value that needs to be passed to the script.
  • To keep in line with the implementation of the hooks implementation, I used the HOOKS_DIR setup as done in pull request #185
  • If the called filter script doesn't exist or is not executable, the returned value is the same as the received one.

Filter names used

filter-flow-hotfix-start-version
filter-flow-release-start-version

petervanderdoes added some commits
@petervanderdoes petervanderdoes Implements universal run_filter_hook function
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
54b01d5
@petervanderdoes petervanderdoes Adds filter to git flow hotfix start
Example of the filter script added.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
22ccaed
@petervanderdoes petervanderdoes Adds filter hook version in for release start
Also adds sample script.

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
104af03
@petervanderdoes petervanderdoes Adds some comments to the sample scripts
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
a0a40e1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 4, 2012
  1. @petervanderdoes

    Implements universal run_filter_hook function

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

    Adds filter to git flow hotfix start

    petervanderdoes authored
    Example of the filter script added.
    
    Signed-off-by: Peter van der Does <peter@avirtualhome.com>
  3. @petervanderdoes

    Adds filter hook version in for release start

    petervanderdoes authored
    Also adds sample script.
    
    Signed-off-by: Peter van der Does <peter@avirtualhome.com>
  4. @petervanderdoes

    Adds some comments to the sample scripts

    petervanderdoes authored
    Signed-off-by: Peter van der Does <peter@avirtualhome.com>
This page is out of date. Refresh to see the latest.
View
4 git-flow-hotfix
@@ -157,6 +157,10 @@ cmd_start() {
DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
parse_args "$@"
BASE=${2:-$MASTER_BRANCH}
+ # Run filter on the version
+ VERSION=`run_filter_hook hotfix-start-version $VERSION`
+ # As VERSION might have changed reset BRANCH with new VERSION
+ BRANCH=$PREFIX$VERSION
require_version_arg
require_base_is_on_master
require_no_existing_hotfix_branches
View
4 git-flow-release
@@ -153,6 +153,10 @@ cmd_start() {
DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
parse_args "$@"
BASE=${2:-$DEVELOP_BRANCH}
+ # Run filter on the version
+ VERSION=`run_filter_hook release-start-version $VERSION`
+ # As VERSION might have changed reset BRANCH with new VERSION
+ BRANCH=$PREFIX$VERSION
require_version_arg
require_base_is_on_develop
require_no_existing_release_branches
View
22 gitflow-common
@@ -186,6 +186,7 @@ gitflow_is_initialized() {
# loading settings that can be overridden using git config
gitflow_load_settings() {
export DOT_GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+ export HOOKS_DIR="$DOT_GIT_DIR"/hooks
export MASTER_BRANCH=$(git config --get gitflow.branch.master)
export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop)
export ORIGIN=$(git config --get gitflow.origin || echo origin)
@@ -316,3 +317,24 @@ require_branches_equal() {
fi
fi
}
+
+#
+# run_filter_hook
+#
+# Looks for a Git hook script called as defined by the first variable
+#
+# filter-flow-command
+#
+# If such a hook script exists and is executable, it is called with the given
+# positional arguments.
+#
+run_filter_hook() {
+ local command=$1
+ shift
+ local scriptfile="${HOOKS_DIR}/filter-flow-${command}"
+ if [ -x $scriptfile ]; then
+ echo `$scriptfile "$@"`
+ else
+ echo "$@"
+ fi
+}
View
17 hooks/filter-flow-hotfix-start-version
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# Runs during git flow hotfix start
+#
+# Positional arguments:
+# $1 Version
+#
+# Return VERSION - When VERSION is returned empty gitflow
+# will stop as the version is necessary
+#
+VERSION=$1
+
+# Implement your script here.
+
+# Return the VERSION
+echo ${VERSION}
+exit 0
View
17 hooks/filter-flow-release-start-version
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# Runs during git flow release start
+#
+# Positional arguments:
+# $1 Version
+#
+# Return VERSION - When VERSION is returned empty gitflow
+# will stop as the version is necessary
+#
+VERSION=$1
+
+# Implement your script here.
+
+# Return the VERSION
+echo ${VERSION}
+exit 0
Something went wrong with that request. Please try again.