Skip to content
This repository

Feature/implement version filter #186

Open
wants to merge 4 commits into from

1 participant

Peter van der Does
Peter van der Does

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

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

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

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
104af03
Peter van der Does 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

Showing 4 unique commits by 1 author.

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

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

Signed-off-by: Peter van der Does <peter@avirtualhome.com>
104af03
Peter van der Does Adds some comments to the sample scripts
Signed-off-by: Peter van der Does <peter@avirtualhome.com>
a0a40e1
This page is out of date. Refresh to see the latest.
4  git-flow-hotfix
@@ -157,6 +157,10 @@ cmd_start() {
157 157
 	DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
158 158
 	parse_args "$@"
159 159
 	BASE=${2:-$MASTER_BRANCH}
  160
+	# Run filter on the version
  161
+	VERSION=`run_filter_hook hotfix-start-version $VERSION`
  162
+	# As VERSION might have changed reset BRANCH with new VERSION
  163
+	BRANCH=$PREFIX$VERSION
160 164
 	require_version_arg
161 165
 	require_base_is_on_master
162 166
 	require_no_existing_hotfix_branches
4  git-flow-release
@@ -153,6 +153,10 @@ cmd_start() {
153 153
 	DEFINE_boolean fetch false "fetch from $ORIGIN before performing finish" F
154 154
 	parse_args "$@"
155 155
 	BASE=${2:-$DEVELOP_BRANCH}
  156
+	# Run filter on the version
  157
+	VERSION=`run_filter_hook release-start-version $VERSION`
  158
+	# As VERSION might have changed reset BRANCH with new VERSION
  159
+	BRANCH=$PREFIX$VERSION
156 160
 	require_version_arg
157 161
 	require_base_is_on_develop
158 162
 	require_no_existing_release_branches
22  gitflow-common
@@ -186,6 +186,7 @@ gitflow_is_initialized() {
186 186
 # loading settings that can be overridden using git config
187 187
 gitflow_load_settings() {
188 188
 	export DOT_GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
  189
+	export HOOKS_DIR="$DOT_GIT_DIR"/hooks
189 190
 	export MASTER_BRANCH=$(git config --get gitflow.branch.master)
190 191
 	export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop)
191 192
 	export ORIGIN=$(git config --get gitflow.origin || echo origin)
@@ -316,3 +317,24 @@ require_branches_equal() {
316 317
 		fi
317 318
 	fi
318 319
 }
  320
+
  321
+#
  322
+# run_filter_hook
  323
+#
  324
+# Looks for a Git hook script called as defined by the first variable
  325
+#
  326
+#     filter-flow-command
  327
+#
  328
+# If such a hook script exists and is executable, it is called with the given
  329
+# positional arguments.
  330
+#
  331
+run_filter_hook() {
  332
+	local command=$1
  333
+	shift
  334
+	local scriptfile="${HOOKS_DIR}/filter-flow-${command}"
  335
+	if [ -x $scriptfile ]; then
  336
+		echo `$scriptfile "$@"`
  337
+	else
  338
+		echo "$@"
  339
+	fi
  340
+}
17  hooks/filter-flow-hotfix-start-version
... ...
@@ -0,0 +1,17 @@
  1
+#!/bin/sh
  2
+#
  3
+# Runs during git flow hotfix start
  4
+#
  5
+# Positional arguments:
  6
+# $1    Version
  7
+#
  8
+# Return VERSION - When VERSION is returned empty gitflow 
  9
+#	will stop as the version is necessary
  10
+#
  11
+VERSION=$1
  12
+
  13
+# Implement your script here.
  14
+
  15
+# Return the VERSION
  16
+echo ${VERSION}
  17
+exit 0
17  hooks/filter-flow-release-start-version
... ...
@@ -0,0 +1,17 @@
  1
+#!/bin/sh
  2
+#
  3
+# Runs during git flow release start
  4
+#
  5
+# Positional arguments:
  6
+# $1    Version
  7
+#
  8
+# Return VERSION - When VERSION is returned empty gitflow 
  9
+#	will stop as the version is necessary
  10
+#
  11
+VERSION=$1
  12
+
  13
+# Implement your script here.
  14
+
  15
+# Return the VERSION
  16
+echo ${VERSION}
  17
+exit 0
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.