├── config.sh ├── jshint.json ├── hooks_config.sample ├── modules ├── prevent-master-commit.sh ├── prevent-merge-marker-commits.sh ├── debug.sh ├── phplint.sh └── jshint.sh ├── commit-msg ├── pre-flow-hotfix-finish ├── post-flow-release-start ├── pre-flow-release-finish ├── pre-commit ├── post-commit ├── filter-flow-hotfix-start-version ├── filter-flow-release-start-version ├── post-flow-hotfix-start ├── post-flow-release-finish ├── pre-flow-bugfix-finish ├── pre-flow-feature-finish ├── prepare-commit-msg ├── README.mdown └── gitflow-functions /config.sh: -------------------------------------------------------------------------------- 1 | # pre-commit 2 | #pre_commit_modules="jshint.sh phplint.sh prevent-master-commit.sh prevent-merge-marker-commits.sh" 3 | pre_commit_modules="prevent-master-commit.sh prevent-merge-marker-commits.sh" -------------------------------------------------------------------------------- /jshint.json: -------------------------------------------------------------------------------- 1 | { 2 | "browser": true, 3 | "predef": [ "jQuery", "BBBX", "$", "contain", "asyncTest" ], 4 | "strict": true, 5 | "white": true, 6 | "undef": true, 7 | "unused": false, 8 | "trailing": true, 9 | "camelcase": false 10 | } -------------------------------------------------------------------------------- /hooks_config.sample: -------------------------------------------------------------------------------- 1 | MAINFILE=Changes.mdown 2 | 3 | _update_version() { 4 | #Update the version number 5 | sed -i 's/^GITFLOW_VERSION=.*/GITFLOW_VERSION='$1'/' $ROOTDIR/git-flow-version 6 | sed -i '0,/####.*/s/^####.*/#### '$1'/' $ROOTDIR/Changes.mdown 7 | } 8 | -------------------------------------------------------------------------------- /modules/prevent-master-commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | h1 "Master protection" 4 | 5 | branch=`git symbolic-ref HEAD` 6 | if [ "$branch" = "refs/heads/master" ]; then 7 | gitflow_fail "Direct commits to the branch master are not allowed" 8 | exit 1 9 | else 10 | gitflow_ok "Branch is not master" 11 | fi -------------------------------------------------------------------------------- /modules/prevent-merge-marker-commits.sh: -------------------------------------------------------------------------------- 1 | h1 "Prevent merge marker commits" 2 | 3 | ERROR=0 4 | for file in $(gitflow_commit_files); do 5 | if grep -Erls "^<<<<<<< |^>>>>>>>" $file >/dev/null ; then 6 | gitflow_fail $file 7 | ERROR=1 8 | fi 9 | done 10 | 11 | if [ $ERROR -eq 0 ]; then 12 | gitflow_ok "No merge markers found" 13 | fi 14 | 15 | return $ERROR -------------------------------------------------------------------------------- /modules/debug.sh: -------------------------------------------------------------------------------- 1 | if [ $(gitflow_count_commit_files php) -eq 0 ] ; then 2 | return 0 3 | fi 4 | 5 | h1 "Debug code detect module" 6 | 7 | ERROR=0 8 | for file in $(gitflow_commit_files php); do 9 | if egrep -n 'debugger|alert' $file >/dev/null ; then 10 | gitflow_fail $file 11 | egrep -n 'debugger|alert' $file 12 | ERROR=1 13 | else 14 | gitflow_ok $file 15 | fi 16 | done 17 | 18 | return $ERROR -------------------------------------------------------------------------------- /modules/phplint.sh: -------------------------------------------------------------------------------- 1 | if [ $(gitflow_count_commit_files php) -eq 0 ] ; then 2 | return 0 3 | fi 4 | 5 | h1 "PHPLint module" 6 | 7 | ERROR=0 8 | for file in $(gitflow_commit_files php); do 9 | if php -l $file 2>&1 | grep 'No syntax errors' >/dev/null ; then 10 | gitflow_ok $file 11 | else 12 | gitflow_fail $file 13 | echo $(php -l $file) | sed "s/^/ ${GREY}--> /" 14 | ERROR=1 15 | fi 16 | done 17 | 18 | return $ERROR -------------------------------------------------------------------------------- /modules/jshint.sh: -------------------------------------------------------------------------------- 1 | if [ $(gitflow_count_commit_files js) -eq 0 ] ; then 2 | return 0 3 | fi 4 | 5 | JSHINT="jshint" 6 | 7 | h1 "JSHint module" 8 | 9 | ERROR=0 10 | for file in $(gitflow_commit_files js); do 11 | if $JSHINT --config="$HOOKS_DIR"/jshint.json $file 2>&1 | grep 'error' >/dev/null ; then 12 | gitflow_fail $file 13 | $JSHINT --config="$HOOKS_DIR"/jshint.json $file | sed "s/^/ ${GREY}--> /" | sed '$ d' | sed '$ d' 14 | ERROR=1 15 | else 16 | gitflow_ok $file 17 | fi 18 | done 19 | 20 | return $ERROR -------------------------------------------------------------------------------- /commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REPO_DIR=$(git rev-parse --show-toplevel) 3 | DOT_GIT_DIR=$(git rev-parse --git-dir) 4 | if [ "$DOT_GIT_DIR" = ".git" ]; then 5 | DOT_GIT_DIR="$REPO_DIR"/"$DOT_GIT_DIR" 6 | fi 7 | HOOKS_DIR="$DOT_GIT_DIR"/hooks 8 | . "$HOOKS_DIR"/gitflow-functions 9 | 10 | HOOK_ERROR=0 11 | MESSAGE=$(cat $1) 12 | LEN=$(echo ${#MESSAGE}) 13 | 14 | if [ $LEN -lt 8 ]; then 15 | echo "${CROSS}${RED} Such a short commit message? Give this commit a real meaning with a good commit message!${WHITE}" 16 | echo "" 17 | HOOK_ERROR=1 18 | fi 19 | 20 | exit $HOOK_ERROR -------------------------------------------------------------------------------- /pre-flow-hotfix-finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs before git flow hotfix finish 4 | # 5 | # Positional arguments: 6 | # $1 The version (including the version prefix) 7 | # $2 The origin remote 8 | # $3 The full branch name (including the feature prefix) 9 | # 10 | VERSION=$1 11 | ORIGIN=$2 12 | BRANCH=$3 13 | 14 | # Implement your script here. 15 | . "$HOOKS_DIR"/gitflow-functions 16 | ROOTDIR=$(git rev-parse --show-toplevel) 17 | 18 | gitflow_update_authors 19 | 20 | gitflow_update_version $VERSION 21 | 22 | # To terminate the git-flow action, return a non-zero exit code. 23 | exit 0 24 | -------------------------------------------------------------------------------- /post-flow-release-start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs at the end of git flow release finish 4 | # 5 | # Positional arguments: 6 | # $1 The version (including the version prefix) 7 | # $2 The origin remote 8 | # $3 The full branch name (including the release prefix) 9 | # 10 | VERSION=$1 11 | ORIGIN=$2 12 | BRANCH=$3 13 | 14 | # Implement your script aere. 15 | . "$HOOKS_DIR"/gitflow-functions 16 | ROOTDIR=$(git rev-parse --show-toplevel) 17 | TMPFILE=$(mktemp --suffix=.gitflow) 18 | 19 | gitflow_set_major_minor $VERSION 20 | AVH_PRE_RELEASE="-rc.1" 21 | gitflow_build_version 22 | gitflow_update_version $AVH_VERSION 23 | 24 | # To terminate the git-flow action, return a non-zero exit code. 25 | exit 0 26 | -------------------------------------------------------------------------------- /pre-flow-release-finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs before git flow release finish 4 | # 5 | # Positional arguments: 6 | # $1 The version (including the version prefix) 7 | # $2 The origin remote 8 | # $3 The full branch name (including the release prefix) 9 | # 10 | # The following variables are available as they are exported by git-flow: 11 | # 12 | # MASTER_BRANCH - The branch defined as Master 13 | # DEVELOP_BRANCH - The branch defined as Develop 14 | # 15 | VERSION=$1 16 | ORIGIN=$2 17 | BRANCH=$3 18 | 19 | # Implement your script here. 20 | . "$HOOKS_DIR"/gitflow-functions 21 | ROOTDIR=$(git rev-parse --show-toplevel) 22 | 23 | gitflow_update_authors 24 | gitflow_update_version $VERSION 25 | 26 | # To terminate the git-flow action, return a non-zero exit code. 27 | exit 0 28 | -------------------------------------------------------------------------------- /pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | REPO_DIR=$(git rev-parse --show-toplevel) 3 | DOT_GIT_DIR=$(git rev-parse --git-dir) 4 | if [ "$DOT_GIT_DIR" = ".git" ]; then 5 | DOT_GIT_DIR="$REPO_DIR"/"$DOT_GIT_DIR" 6 | fi 7 | HOOKS_DIR="$DOT_GIT_DIR"/hooks 8 | . "$HOOKS_DIR"/gitflow-functions 9 | . "$HOOKS_DIR"/config.sh 10 | 11 | HOOK_ERROR=0 12 | 13 | echo ${WHITE} 14 | 15 | for module in $pre_commit_modules; do 16 | module_path="$HOOKS_MODULES_DIR/$module" 17 | [ ! -e $module_path ] && continue 18 | . "$HOOKS_MODULES_DIR/$module" 19 | if [ $? -eq 1 ] ; then 20 | HOOK_ERROR=1 21 | fi 22 | done 23 | 24 | if [ $HOOK_ERROR -eq 1 ] ; then 25 | echo "\n${CROSS}${RED} Time to fix your code!\n" 26 | else 27 | echo "\n${CHECK}${GREEN} Good job!\n" 28 | fi 29 | 30 | echo ${WHITE} 31 | exit $HOOK_ERROR -------------------------------------------------------------------------------- /post-commit: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REPO_DIR=$(git rev-parse --show-toplevel) 3 | DOT_GIT_DIR=$(git rev-parse --git-dir) 4 | if [ "$DOT_GIT_DIR" = ".git" ]; then 5 | DOT_GIT_DIR="$REPO_DIR"/"$DOT_GIT_DIR" 6 | fi 7 | HOOKS_DIR="$DOT_GIT_DIR"/hooks 8 | . "$HOOKS_DIR"/gitflow-functions 9 | 10 | # Hook for the Git time tracker that we use 11 | #hacking=$(git config --local timetrack.hacking) 12 | #git timetrack -p > /dev/null 13 | #spent=$(git config --local timetrack.spent) 14 | #git config --local --remove-section timetrack 2> /dev/null 15 | 16 | #if [ $spent ] 17 | #then 18 | # git notes --ref timetracker add -m "Time-spent: $spent" 19 | # 20 | # if [ $hacking ] 21 | # then 22 | # git config --local timetrack.start $(date +%s) 23 | # git config --local timetrack.hacking $hacking 24 | # fi 25 | #fi -------------------------------------------------------------------------------- /filter-flow-hotfix-start-version: -------------------------------------------------------------------------------- 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 | . "$HOOKS_DIR"/gitflow-functions 15 | ROOTDIR=$(git rev-parse --show-toplevel) 16 | current_branch=$(git rev-parse --abbrev-ref HEAD) 17 | 18 | gitflow_set_major_minor $VERSION 19 | 20 | git checkout -q "$MASTER_BRANCH" 21 | VERSION=$(grep -m1 "GITFLOW_VERSION=" $ROOTDIR/git-flow-version | cut -f2 -d"=") 22 | gitflow_set_major_minor $VERSION 23 | AVH_PATCH_LEVEL=$(($AVH_PATCH_LEVEL+1)) 24 | git checkout -q $current_branch 25 | 26 | gitflow_build_version 27 | 28 | # Return the VERSION 29 | echo ${AVH_VERSION} 30 | exit 0 31 | -------------------------------------------------------------------------------- /filter-flow-release-start-version: -------------------------------------------------------------------------------- 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 | . "$HOOKS_DIR"/gitflow-functions 15 | ROOTDIR=$(git rev-parse --show-toplevel) 16 | current_branch=$(git rev-parse --abbrev-ref HEAD) 17 | 18 | if [ -z "$VERSION" ]; then 19 | git checkout -q "$MASTER_BRANCH" 20 | VERSION=$(grep -m1 "GITFLOW_VERSION=" $ROOTDIR/git-flow-version | cut -f2 -d"=") 21 | gitflow_set_major_minor $VERSION 22 | AVH_PATCH_LEVEL=$(($AVH_PATCH_LEVEL+1)) 23 | git checkout -q $current_branch 24 | else 25 | TAG=`git tag $VERSION* -l|grep -v -| tail -1` 26 | if [ -z "$TAG" ]; then 27 | gitflow_set_major_minor $VERSION 28 | else 29 | gitflow_set_major_minor $TAG 30 | AVH_PATCH_LEVEL=$(($AVH_PATCH_LEVEL+1)) 31 | fi 32 | fi 33 | gitflow_build_version 34 | 35 | # Return the VERSION 36 | echo "${AVH_VERSION}" 37 | exit 0 38 | -------------------------------------------------------------------------------- /post-flow-hotfix-start: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs at the end of git flow hotfix start 4 | # 5 | # Positional arguments: 6 | # $1 The version (including the version prefix) 7 | # $2 The origin remote 8 | # $3 The full branch name (including the feature prefix) 9 | # $4 The base from which this feature is started 10 | # 11 | VERSION=$1 12 | ORIGIN=$2 13 | BRANCH=$3 14 | BASE=$4 15 | 16 | # Implement your script here. 17 | . "$HOOKS_DIR"/gitflow-functions 18 | ROOTDIR=$(git rev-parse --show-toplevel) 19 | TMPFILE=$(mktemp --suffix=.gitflow) 20 | 21 | LINENUMBER=$(($(grep -m1 -n "^#### " $ROOTDIR/Changes.mdown | cut -f1 -d:) -1 )) 22 | sed ''$LINENUMBER'a#### '$VERSION'\n* Preparation for hotfix.\n' $ROOTDIR/Changes.mdown > $TMPFILE 23 | cp $TMPFILE $ROOTDIR/Changes.mdown 24 | 25 | gitflow_set_major_minor $VERSION 26 | AVH_PRE_RELEASE="-rc.1" 27 | gitflow_build_version 28 | gitflow_update_version $AVH_VERSION "Start of hotfix development" 29 | 30 | #Clean up 31 | rm -f $TMPFILE 32 | 33 | # To terminate the git-flow action, return a non-zero exit code. 34 | exit 0 35 | -------------------------------------------------------------------------------- /post-flow-release-finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs at the end of git flow release finish 4 | # 5 | # Positional arguments: 6 | # $1 The version (including the version prefix) 7 | # $2 The origin remote 8 | # $3 The full branch name (including the release prefix) 9 | # 10 | VERSION=$1 11 | ORIGIN=$2 12 | BRANCH=$3 13 | 14 | # Implement your script aere. 15 | . "$HOOKS_DIR"/gitflow-functions 16 | ROOTDIR=$(git rev-parse --show-toplevel) 17 | 18 | git checkout $DEVELOP_BRANCH 19 | TMPFILE=$(mktemp --suffix=.gitflow) 20 | 21 | gitflow_set_major_minor $VERSION 22 | AVH_MINOR=$(($AVH_MINOR+1)) 23 | AVH_PATCH_LEVEL=0 24 | gitflow_set_dev_release 25 | gitflow_build_version 26 | 27 | LINENUMBER=$(($(grep -m1 -n "^#### " $ROOTDIR/Changes.mdown | cut -f1 -d:) -1 )) 28 | sed ''$LINENUMBER'a#### '$AVH_VERSION' =\n* Preparation for new development cycle.\n' $ROOTDIR/Changes.mdown > $TMPFILE 29 | cp $TMPFILE $ROOTDIR/Changes.mdown 30 | 31 | gitflow_update_version $AVH_VERSION "Preparation for new development cycle after release $VERSION" 32 | 33 | git checkout $BRANCH 34 | #Clean up 35 | rm -f $TMPFILE 36 | 37 | # To terminate the git-flow action, return a non-zero exit code. 38 | exit 0 39 | -------------------------------------------------------------------------------- /pre-flow-bugfix-finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs before git flow bugfix finish 4 | # 5 | # Positional arguments: 6 | # $1 The friendly name of the branch 7 | # $2 The origin remote 8 | # $3 The full branch name (including the feature prefix) 9 | # 10 | NAME=$1 11 | ORIGIN=$2 12 | BRANCH=$3 13 | 14 | # Implement your script here. 15 | . "$HOOKS_DIR"/gitflow-functions 16 | 17 | ROOTDIR=$(git rev-parse --show-toplevel) 18 | 19 | gitflow_update_authors 20 | 21 | # Prepare new version 22 | # HOOKS_DIR is defined in gitflow-common. 23 | CURRENT_VERSION=$(gitflow_get_current_version) 24 | 25 | gitflow_set_major_minor $CURRENT_VERSION 26 | gitflow_set_dev_release 27 | gitflow_build_version 28 | 29 | # If the branch names ends with _nr where nr is a number it adds the line Closes #nr 30 | # This makes github automatically close that issue when the develop branch is pushed. 31 | ISSUENR=$(echo ${NAME##*_}) 32 | if gitflow_validInt "$ISSUENR"; then 33 | MESSAGE="Version bump $AVH_VERSION 34 | 35 | Closes #$ISSUENR 36 | " 37 | else 38 | MESSAGE="" 39 | fi 40 | 41 | gitflow_update_version $AVH_VERSION "$MESSAGE" 42 | 43 | #Clean up 44 | # To terminate the git-flow action, return a non-zero exit code. 45 | exit 0 46 | -------------------------------------------------------------------------------- /pre-flow-feature-finish: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Runs before git flow feature finish 4 | # 5 | # Positional arguments: 6 | # $1 The friendly name of the branch 7 | # $2 The origin remote 8 | # $3 The full branch name (including the feature prefix) 9 | # 10 | NAME=$1 11 | ORIGIN=$2 12 | BRANCH=$3 13 | 14 | # Implement your script here. 15 | . "$HOOKS_DIR"/gitflow-functions 16 | 17 | ROOTDIR=$(git rev-parse --show-toplevel) 18 | 19 | gitflow_update_authors 20 | 21 | # Prepare new version 22 | # HOOKS_DIR is defined in gitflow-common. 23 | CURRENT_VERSION=$(gitflow_get_current_version) 24 | 25 | gitflow_set_major_minor $CURRENT_VERSION 26 | gitflow_set_dev_release 27 | gitflow_build_version 28 | 29 | # If the branch names ends with _nr where nr is a number it adds the line Closes #nr 30 | # This makes github automatically close that issue when the develop branch is pushed. 31 | ISSUENR=$(echo ${NAME##*_}) 32 | if gitflow_validInt "$ISSUENR"; then 33 | MESSAGE="Version bump $AVH_VERSION 34 | 35 | Closes #$ISSUENR 36 | " 37 | else 38 | MESSAGE="" 39 | fi 40 | 41 | gitflow_update_version $AVH_VERSION "$MESSAGE" 42 | 43 | #Clean up 44 | # To terminate the git-flow action, return a non-zero exit code. 45 | exit 0 46 | -------------------------------------------------------------------------------- /prepare-commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | REPO_DIR=$(git rev-parse --show-toplevel) 3 | DOT_GIT_DIR=$(git rev-parse --git-dir) 4 | if [ "$DOT_GIT_DIR" = ".git" ]; then 5 | DOT_GIT_DIR="$REPO_DIR"/"$DOT_GIT_DIR" 6 | fi 7 | HOOKS_DIR="$DOT_GIT_DIR"/hooks 8 | . "$HOOKS_DIR"/gitflow-functions 9 | 10 | # 11 | # An example hook script to prepare the commit log message. 12 | # Called by "git commit" with the name of the file that has the 13 | # commit message, followed by the description of the commit 14 | # message's source. The hook's purpose is to edit the commit 15 | # message file. If the hook fails with a non-zero status, 16 | # the commit is aborted. 17 | # 18 | # To enable this hook, rename this file to "prepare-commit-msg". 19 | 20 | # This hook includes three examples. The first comments out the 21 | # "Conflicts:" part of a merge commit. 22 | # 23 | # The second includes the output of "git diff --name-status -r" 24 | # into the message, just before the "git status" output. It is 25 | # commented because it doesn't cope with --amend or with squashed 26 | # commits. 27 | # 28 | # The third example adds a Signed-off-by line to the message, that can 29 | # still be edited. This is rarely a good idea. 30 | 31 | case "$2,$3" in 32 | merge,) 33 | /usr/bin/perl -i.bak -ne 's/^/# /, s/^# #/#/ if /^Conflicts/ .. /#/; print' "$1" ;; 34 | 35 | # ,|template,) 36 | # /usr/bin/perl -i.bak -pe ' 37 | # print "\n" . `git diff --cached --name-status -r` 38 | # if /^#/ && $first++ == 0' "$1" ;; 39 | 40 | *) ;; 41 | esac 42 | 43 | # SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') 44 | # grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" 45 | -------------------------------------------------------------------------------- /README.mdown: -------------------------------------------------------------------------------- 1 | # git-flow AVH Edition development git hooks 2 | 3 | This is a collection of git hooks to be used in conjunction with git-flow AVH 4 | edition. 5 | 6 | It also has some standard git hooks that were originally created by [Sitebase](https://github.com/Sitebase/git-hooks). 7 | I just adjusted their code to make it work for me. 8 | 9 | These hooks are used by me for development of git-flow AVH Edition itself 10 | 11 | ## Installation 12 | * Clone the repository 13 | * Create a softlink in your repository .git directory named hooks. If the 14 | directory exists, just delete it. 15 | * Copy the file hooks_config.sample to the .git directory, naming it hooks_config. 16 | * Make the needed adjustments to the hooks_config file. 17 | 18 | ## Requirements 19 | * git-flow AVH edition 20 | * Bash shell script. 21 | * Use the [Semantic Versioning 2.0.0](http://semver.org/) specification. 22 | 23 | ## Information 24 | 25 | * When you start a release you can omit the version number. The filter will grep 26 | the version set in the stable info of the master branch and increase the patch level. 27 | * You can't commit on a master branch. 28 | * You can't commit files with merge markers. 29 | * Commit messages shorter than 8 are not allowed. 30 | 31 | ## hooks_config file 32 | There should be no need to make adjustments to the hooks_config file 33 | 34 | ## License 35 | Portions of the code is licensed as The MIT License 36 | 37 | Copyright (c) 2013 Wim Mostmans 38 | 39 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 40 | 41 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 44 | 45 | -------------------------------------------------------------------------------- /gitflow-functions: -------------------------------------------------------------------------------- 1 | # Version variables 2 | AVH_MAJOR="" 3 | AVH_MINOR="" 4 | AVH_PATCH_LEVEL="" 5 | AVH_PRE_RELEASE="" 6 | AVH_VERSION="" 7 | 8 | # Colors 9 | RED=`printf '\033[1;31m'` 10 | GREEN=`printf '\033[1;32m'` 11 | WHITE=`printf '\033[1;37m'` 12 | GREY=`printf '\033[1;36m'` 13 | 14 | # Icons 15 | CHECK=`printf ${GREEN}'✔'${WHITE}` 16 | CROSS=`printf ${RED}'✘'${WHITE}` 17 | 18 | # Modules directory 19 | HOOKS_MODULES_DIR="$HOOKS_DIR"/modules 20 | 21 | REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)" 22 | if [ ! -f "$REPO_DIR"/.git/hooks_config ]; then 23 | echo "\n${CROSS}${RED} Missing file "$REPO_DIR"/.git/hooks_config" 24 | exit 127 25 | fi 26 | . "$REPO_DIR"/.git/hooks_config 27 | 28 | type _update_version >/dev/null 2>&1; 29 | if [ $? -eq 127 ]; then 30 | echo "\n${CROSS}${RED} Missing function _update_version!\nThis function should be declared in "$REPO_DIR"/.git/hooks_config" 31 | exit 127 32 | fi 33 | 34 | gitflow_update_version() { 35 | if [ -n "$2" ]; then 36 | MSG="$2" 37 | else 38 | MSG="Version bump $1" 39 | fi 40 | _update_version $1 41 | git commit -a -m "$MSG" 42 | } 43 | 44 | gitflow_set_major_minor() { 45 | local TEMP_VERSION=$1 46 | AVH_MAJOR=$(echo "$TEMP_VERSION" | cut -f1 -d".") 47 | if $(gitflow_contains "$TEMP_VERSION" "."); then 48 | TEMP_VERSION=$(echo ${TEMP_VERSION#*.}) 49 | AVH_MINOR=$(echo "$TEMP_VERSION" | cut -f1 -d"."|cut -f1 -d"-") 50 | if [ -z $AVH_MINOR ]; then 51 | AVH_MINOR=0 52 | AVH_PATCH_LEVEL=0 53 | else 54 | if $(gitflow_contains "$TEMP_VERSION" "."); then 55 | TEMP_VERSION=$(echo ${TEMP_VERSION#*.}) 56 | AVH_PATCH_LEVEL=$(echo "$TEMP_VERSION" | cut -f1 -d"."|cut -f1 -d"-") 57 | [ -z $AVH_PATCH_LEVEL ] && AVH_PATCH_LEVEL=0 58 | else 59 | AVH_PATCH_LEVEL=0 60 | fi 61 | fi 62 | else 63 | AVH_MINOR=0 64 | AVH_PATCH_LEVEL=0 65 | fi 66 | } 67 | 68 | gitflow_build_version() { 69 | AVH_VERSION=$AVH_MAJOR.$AVH_MINOR.$AVH_PATCH_LEVEL 70 | [ -n AVH_PRE_RELEASE ] && AVH_VERSION=$AVH_VERSION$AVH_PRE_RELEASE 71 | } 72 | 73 | # 74 | # Set the pre-release, it counts all commits but not the one in master 75 | # 76 | gitflow_set_dev_release() { 77 | AVH_PRE_RELEASE=-dev.$(git rev-list --count HEAD ^"$MASTER_BRANCH") 78 | } 79 | 80 | # 81 | # Set the rc-release, it counts all commits but not the one in master 82 | # 83 | gitflow_set_rc_release() { 84 | local RC_LEVEL=$(echo "$1" | cut -f2 -d"-"|cut -f2 -d".") 85 | RC_LEVEL=$(($RC_LEVEL+1)) 86 | AVH_PRE_RELEASE=-rc.$RC_LEVEL 87 | } 88 | 89 | gitflow_get_current_version() { 90 | CURRENT_VERSION=$(grep -m1 "GITFLOW_VERSION=" $ROOTDIR/git-flow-version | cut -f2 -d"=") 91 | echo "$CURRENT_VERSION" 92 | } 93 | 94 | # 95 | # Create an up to date AUTHORS file 96 | # 97 | gitflow_update_authors() { 98 | ROOTDIR=$(git rev-parse --show-toplevel) 99 | AUTHORS=$(mktemp --suffix=.gitflow) 100 | 101 | # Create an up to date AUTHORS file 102 | echo "git-flow AVH Authors 103 | 104 | This software consists of voluntary contributions made by many 105 | individuals. For exact contribution history, see the revision history 106 | (Changes.mdown) and logs, available at 107 | http://github.com/petervanderdoes/gitflow. 108 | 109 | " > $AUTHORS 110 | git shortlog -ns --no-merges | cut -f2 >> $AUTHORS 111 | echo " 112 | 113 | Portions of the project are derived from other open source works are clearly 114 | marked. 115 | 116 | This file is auto generated, any changes will be lost." >> $AUTHORS 117 | 118 | # Check if the new file is different 119 | # If it's not there is no need to copy it and commit 120 | diff $AUTHORS $ROOTDIR/AUTHORS > /dev/null 2>&1 121 | DIFF=$? 122 | if [ $DIFF -ne 0 ]; then 123 | cp $AUTHORS $ROOTDIR/AUTHORS 124 | git commit AUTHORS -m "Update of the contributers." 125 | fi 126 | # Clean up 127 | rm $AUTHORS 128 | } 129 | 130 | 131 | # 132 | # String contains function 133 | # $1 haystack 134 | # $2 Needle 135 | # 136 | gitflow_contains() { 137 | local return 138 | 139 | case $1 in 140 | *$2*) 141 | return=0 142 | ;; 143 | *) 144 | return=1 145 | ;; 146 | esac 147 | return $return 148 | } 149 | 150 | gitflow_fail() { 151 | echo "\t"${CROSS} ${GREY}$1${WHITE} 152 | } 153 | 154 | gitflow_ok() { 155 | echo "\t"${CHECK} ${GREY}$1${WHITE} 156 | } 157 | 158 | h1() { 159 | echo "\n${WHITE}$1 ...\n" 160 | } 161 | 162 | # Function to get a list of files that will be committed by extension 163 | # you can for example do "$(commit_files js css)" to get a list of js and css files that will be committed 164 | gitflow_commit_files() { 165 | 166 | if [ $# -eq 0 ] ; then 167 | echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD --) 168 | exit 0 169 | fi 170 | 171 | extensions='' 172 | for extension in "$@" 173 | do 174 | extensions="${extensions}(${extension})|" 175 | done 176 | regex="\.(${extensions%?})$" 177 | echo $(git diff-index --name-only --diff-filter=ACM --cached HEAD -- | grep -P "$regex") 178 | } 179 | 180 | gitflow_count_commit_files() { 181 | echo $(gitflow_commit_files $@) | wc -w | tr -d ' ' 182 | } 183 | 184 | gitflow_validInt() { 185 | local _return 186 | 187 | [ -n "$1" ] || return 1 188 | _int="$1" 189 | case "${_int}" in 190 | *[!0-9]*) _return=1 ;; 191 | *) _return=0 ;; 192 | esac 193 | return $_return 194 | } 195 | --------------------------------------------------------------------------------