Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save petervanderdoes/2878492 to your computer and use it in GitHub Desktop.
Save petervanderdoes/2878492 to your computer and use it in GitHub Desktop.
gitflow hooks and filter for gitflow development
#!/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
#!/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
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
}
#!/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
#!/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
#!/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
#!/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
#!/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
#!/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
#!/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment