public

gitflow hooks and filter for gitflow development

  • Download Gist
filter-flow-hotfix-start-version
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/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.
. "$HOOKS_DIR"/gitflow-functions
ROOTDIR=$(git rev-parse --show-toplevel)
current_branch=$(git rev-parse --abbrev-ref HEAD)
 
if [ -z "$VERSION" ]; then
git checkout -q $MASTER_BRANCH
VERSION=$(grep -m1 "^#### " $ROOTDIR/Changes.mdown | cut -f2 -d" ")
gitflow_set_major_minor $VERSION
AVH_PATCH_LEVEL=$(($PATCH_LEVEL+1))
git checkout -q $current_branch
else
gitflow_set_major_minor $VERSION
 
if [ "$AVH_PATCH_LEVEL" -eq "0" ]; then
git checkout -q $MASTER_BRANCH
PATCH_LEVEL=$(grep -m1 "^#### " $ROOTDIR/Changes.mdown | cut -f3 -d"."| cut -f1 -d"-")
AVH_PATCH_LEVEL=$(($PATCH_LEVEL+1))
git checkout -q $current_branch
fi
fi
gitflow_build_version
 
# Return the VERSION
echo ${AVH_VERSION}
exit 0
filter-flow-release-start-version
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/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
if [ -z $VERSION ]; then
echo $VERSION
exit 1
fi
 
# Implement your script here.
. "$HOOKS_DIR"/gitflow-functions
 
gitflow_set_major_minor $VERSION
AVH_PATCH_LEVEL=0
gitflow_build_version
 
# Return the VERSION
echo ${AVH_VERSION}
exit 0
gitflow-functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
AVH_MAJOR=""
AVH_MINOR=""
AVH_PATCH_LEVEL=""
AVH_PRE_RELEASE=""
AVH_VERSION=""
_update_version() {
#Update the version number
sed -i 's/^GITFLOW_VERSION=.*/GITFLOW_VERSION='$1'/' $ROOTDIR/git-flow-version
sed -i '0,/####.*/s/^####.*/#### '$1'/' $ROOTDIR/Changes.mdown
}
 
gitflow_update_version() {
_update_version "$1"
if [ -n "$2" ]; then
MSG="$2"
else
MSG="Version bump $1"
fi
git commit -a -m "$MSG"
}
 
gitflow_set_major_minor() {
local TEMP_VERSION=$1
AVH_MAJOR=$(echo "$TEMP_VERSION" | cut -f1 -d".")
AVH_MINOR=$(echo "$TEMP_VERSION" | cut -f2 -d"."|cut -f1 -d"-")
AVH_PATCH_LEVEL=$(echo "$TEMP_VERSION" | cut -f3 -d"."|cut -f1 -d"-")
[ -z $AVH_PATCH_LEVEL ] && AVH_PATCH_LEVEL=0
}
 
gitflow_build_version() {
AVH_VERSION=$AVH_MAJOR.$AVH_MINOR.$AVH_PATCH_LEVEL
[ -n AVH_PRE_RELEASE ] && AVH_VERSION=$AVH_VERSION$AVH_PRE_RELEASE
}
 
#
# Set the pre-release, it counts all commits but not the one in master
#
gitflow_set_dev_release() {
local master=$(git config --get gitflow.branch.master)
AVH_PRE_RELEASE=-dev.$(git rev-list --count HEAD ^"$master")
}
 
#
# Set the rc-release, it counts all commits but not the one in master
#
gitflow_set_rc_release() {
local RC_LEVEL=$(echo "$1" | cut -f2 -d"-"|cut -f2 -d".")
RC_LEVEL=$(($RC_LEVEL+1))
AVH_PRE_RELEASE=-rc.$RC_LEVEL
}
 
#
# Create an up to date AUTHORS file
#
gitflow_update_authors() {
ROOTDIR=$(git rev-parse --show-toplevel)
AUTHORS=$(mktemp --suffix=.gitflow)
 
# Create an up to date AUTHORS file
echo "git-flow AVH Authors
 
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
(Changes.mdown) and logs, available at
http://github.com/petervanderdoes/gitflow.
 
" > $AUTHORS
git shortlog -ns --no-merges | cut -f2 >> $AUTHORS
echo "
 
Portions of the project are derived from other open source works are clearly
marked.
 
This file is auto generated, any changes will be lost." >> $AUTHORS
 
# Check if the new file is different
# If it's not there is no need to copy it and commit
diff $AUTHORS $ROOTDIR/AUTHORS > /dev/null 2>&1
DIFF=$?
if [ $DIFF -ne 0 ]; then
cp $AUTHORS $ROOTDIR/AUTHORS
git commit -a -m "Update of the contributers."
fi
# Clean up
rm $AUTHORS
}
post-flow-hotfix-start
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#!/bin/sh
#
# Runs at the end of git flow hotfix start
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the feature prefix)
# $4 The base from which this feature is started
#
VERSION=$1
ORIGIN=$2
BRANCH=$3
BASE=$4
 
# Implement your script here.
. "$HOOKS_DIR"/gitflow-functions
ROOTDIR=$(git rev-parse --show-toplevel)
TMPFILE=$(mktemp --suffix=.gitflow)
 
LINENUMBER=$(($(grep -m1 -n "^#### " Changes.mdown | cut -f1 -d:) -1 ))
sed ''$LINENUMBER'a#### '$AVH_VERSION'\n* Preparation hotfix.\n' $ROOTDIR/Changes.mdown > $TMPFILE
cp $TMPFILE $ROOTDIR/Changes.mdown
 
gitflow_set_major_minor $VERSION
AVH_PRE_RELEASE="-rc.1"
gitflow_build_version
gitflow_update_version $AVH_VERSION "Start of hotfix development"
 
#Clean up
rm -f $TMPFILE
 
# To terminate the git-flow action, return a non-zero exit code.
exit 0
post-flow-release-finish
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/bin/sh
#
# Runs at the end of git flow release finish
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
#
VERSION=$1
ORIGIN=$2
BRANCH=$3
 
# Implement your script aere.
. "$HOOKS_DIR"/gitflow-functions
ROOTDIR=$(git rev-parse --show-toplevel)
 
git checkout $DEVELOP_BRANCH
TMPFILE=$(mktemp --suffix=.gitflow)
 
gitflow_set_major_minor $VERSION
AVH_MINOR=$(($AVH_MINOR+1))
gitflow_set_dev_release
gitflow_build_version
 
LINENUMBER=$(($(grep -m1 -n "^#### " Changes.mdown | cut -f1 -d:) -1 ))
sed ''$LINENUMBER'a#### '$AVH_VERSION'\n* Preparation for new development cycle.\n' $ROOTDIR/Changes.mdown > $TMPFILE
cp $TMPFILE $ROOTDIR/Changes.mdown
 
gitflow_update_version $AVH_VERSION "Preparation for new development cycle after release $VERSION"
 
git checkout $BRANCH
#Clean up
rm -f $TMPFILE
 
# To terminate the git-flow action, return a non-zero exit code.
exit 0
post-flow-release-start
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/sh
#
# Runs at the end of git flow release finish
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
#
VERSION=$1
ORIGIN=$2
BRANCH=$3
 
# Implement your script aere.
. "$HOOKS_DIR"/gitflow-functions
ROOTDIR=$(git rev-parse --show-toplevel)
 
gitflow_set_major_minor $VERSION
AVH_PRE_RELEASE="-rc.1"
gitflow_build_version
gitflow_update_version $AVH_VERSION
 
# To terminate the git-flow action, return a non-zero exit code.
exit 0
pre-flow-feature-finish
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/sh
#
# Runs before git flow feature finish
#
# Positional arguments:
# $1 The friendly name of the branch
# $2 The origin remote
# $3 The full branch name (including the feature prefix)
#
NAME=$1
ORIGIN=$2
BRANCH=$3
 
# Implement your script here.
. "$HOOKS_DIR"/gitflow-functions
 
ROOTDIR=$(git rev-parse --show-toplevel)
 
# Prepare new version
# HOOKS_DIR is defined in gitflow-common.
CURRENT_VERSION=$(grep -m1 "^#### " Changes.mdown | cut -f2 -d" ")
 
gitflow_set_major_minor $CURRENT_VERSION
gitflow_set_dev_release
gitflow_build_version
 
gitflow_update_version $AVH_VERSION
 
#Clean up
# To terminate the git-flow action, return a non-zero exit code.
exit 0
pre-flow-hotfix-finish
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#!/bin/sh
#
# Runs before git flow hotfix finish
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the feature prefix)
#
VERSION=$1
ORIGIN=$2
BRANCH=$3
 
# Implement your script here.
. "$HOOKS_DIR"/gitflow-functions
 
gitflow_update_authors
 
ROOTDIR=$(git rev-parse --show-toplevel)
 
# Prepare new version
# HOOKS_DIR is defined in gitflow-common.
CURRENT_VERSION=$(grep -m1 "^#### " Changes.mdown | cut -f2 -d" ")
 
gitflow_set_major_minor $CURRENT_VERSION
gitflow_build_version
 
gitflow_update_version $AVH_VERSION
 
# To terminate the git-flow action, return a non-zero exit code.
exit 0
pre-flow-release-finish
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/bin/sh
#
# Runs before git flow release finish
#
# Positional arguments:
# $1 The version (including the version prefix)
# $2 The origin remote
# $3 The full branch name (including the release prefix)
#
VERSION=$1
ORIGIN=$2
BRANCH=$3
 
# Implement your script here.
. "$HOOKS_DIR"/gitflow-functions
 
ROOTDIR=$(git rev-parse --show-toplevel)
AUTHORS=$(mktemp --suffix=.gitflow)
 
# Create an up to date AUTHORS file
echo "git-flow AVH Authors
 
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
(Changes.mdown) and logs, available at
http://github.com/petervanderdoes/gitflow.
 
" > $AUTHORS
git shortlog -ns --no-merges | cut -f2 >> $AUTHORS
echo "
 
Portions of the project are derived from other open source works are clearly
marked.
 
This file is auto generated, any changes will be lost." >> $AUTHORS
 
# Check if the new file is different
# If it's not there is no need to copy it and commit
diff $AUTHORS $ROOTDIR/AUTHORS > /dev/null 2>&1
DIFF=$?
if [ $DIFF -ne 0 ]; then
cp $AUTHORS $ROOTDIR/AUTHORS
git commit -a -m "Update of the contributers."
fi
 
#Update the version number and commit.
gitflow_update_version $VERSION
 
# Clean up
rm $AUTHORS
 
# To terminate the git-flow action, return a non-zero exit code.
exit 0
prepare-commit-msg
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".
 
# This hook includes three examples. The first comments out the
# "Conflicts:" part of a merge commit.
#
# The second includes the output of "git diff --name-status -r"
# into the message, just before the "git status" output. It is
# commented because it doesn't cope with --amend or with squashed
# commits.
#
# The third example adds a Signed-off-by line to the message, that can
# still be edited. This is rarely a good idea.
 
case "$2,$3" in
merge,)
/usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;;
 
# ,|template,)
# /usr/bin/perl -i.bak -pe '
# print "\n" . `git diff --cached --name-status -r`
# if /^#/ && $first++ == 0' "$1" ;;
 
*) ;;
esac
 
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.