Merge branch 'feature/tidy-up' into develop
diff --git a/Makefile b/Makefile
index 11b0b9d..1da3fa1 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,8 @@
SCRIPT_FILES+=git-flow-release
SCRIPT_FILES+=git-flow-support
SCRIPT_FILES+=git-flow-version
-SCRIPT_FILES+=shFlags.sh
+SCRIPT_FILES+=gitflow-common
+SCRIPT_FILES+=gitflow-shFlags
all:
@echo "usage: make install"
diff --git a/git-flow b/git-flow
index f7a826d..573aa25 100755
--- a/git-flow
+++ b/git-flow
@@ -18,21 +18,13 @@
set -x
fi
-export GIT_DIR=$(git rev-parse --git-dir)
export GITFLOW_DIR=$(dirname "$0")
+export GIT_DIR=$(git rev-parse --git-dir)
export MASTER_BRANCH=$(git config --get gitflow.branch.master || echo master)
export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop || echo develop)
export ORIGIN=$(git config --get gitflow.origin || echo origin)
export README=$(git config --get gitflow.readme || echo README)
-warn() { echo "$@" >&2; }
-die() { warn "$@"; exit 1; }
-
-has() {
- local item=$1; shift
- echo " $@ " | grep -q " $item "
-}
-
usage() {
echo "usage: git flow <subcommand>"
echo
@@ -53,11 +45,12 @@
exit 1
fi
+ # load common functionality
+ . "$GITFLOW_DIR/gitflow-common"
+
# use the shFlags project to parse the command line arguments
- . "$GITFLOW_DIR/shFlags.sh"
+ . "$GITFLOW_DIR/gitflow-shFlags"
FLAGS_PARENT="git flow"
- #DEFINE_boolean quiet 0 'run without output' q
- #DEFINE_boolean verbose 0 'run verbose (more output)' v
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
@@ -73,11 +66,6 @@
die "Not a git repository"
fi
- # get all available branches
- LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //')
- REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //')
- ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
-
# run command
. "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
FLAGS_PARENT="git flow $SUBCOMMAND"
@@ -99,109 +87,6 @@
cmd_$SUBACTION "$@"
}
-gitflow_test_clean_working_tree() {
- if ! git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
- return 1
- elif ! git diff-index --cached --quiet --ignore-submodules HEAD --; then
- return 2
- else
- return 0
- fi
-}
-
-gitflow_require_clean_working_tree() {
- gitflow_test_clean_working_tree
- result=$?
- if [ $result -eq 1 ]; then
- die "fatal: Working tree contains unstaged changes. Aborting."
- fi
- if [ $result -eq 2 ]; then
- die "fatal: Index contains uncommited changes. Aborting."
- fi
-}
-
-gitflow_require_local_branch() {
- if ! has $1 $LOCAL_BRANCHES; then
- die "fatal: Local branch '$1' does not exist and is required."
- fi
-}
-
-gitflow_require_remote_branch() {
- if ! has $1 $REMOTE_BRANCHES; then
- die "Remote branch '$1' does not exist and is required."
- fi
-}
-
-gitflow_require_branch() {
- if ! has $1 $ALL_BRANCHES; then
- die "Branch '$1' does not exist and is required."
- fi
-}
-
-gitflow_require_branch_absent() {
- if has $1 $ALL_BRANCHES; then
- die "Branch '$1' already exists. Pick another name."
- fi
-}
-
-#
-# gitflow_test_branches_equal()
-#
-# Tests whether branches and their "origin" counterparts have diverged and need
-# merging first. It returns error codes to provide more detail, like so:
-#
-# 0 Branch heads point to the same commit
-# 1 First given branch needs fast-forwarding
-# 2 Second given branch needs fast-forwarding
-# 3 Branch needs a real merge
-#
-gitflow_test_branches_equal() {
- commit1=$(git rev-parse "$1")
- commit2=$(git rev-parse "$2")
- if [ "$commit1" != "$commit2" ]; then
- base=$(git merge-base "$commit1" "$commit2")
- if [ "$commit1" = "$base" ]; then
- return 1
- elif [ "$commit2" = "$base" ]; then
- return 2
- else
- return 3
- fi
- else
- return 0
- fi
-}
-
-gitflow_require_branches_equal() {
- gitflow_require_local_branch "$1"
- gitflow_require_remote_branch "$2"
- gitflow_test_branches_equal "$1" "$2"
- status=$?
- if [ $status -gt 0 ]; then
- warn "Branches '$1' and '$2' have diverged."
- if [ $status -eq 1 ]; then
- die "And branch '$1' may be fast-forwarded."
- elif [ $status -eq 2 ]; then
- # Warn here, since there is no harm in being ahead
- warn "And local branch '$1' is ahead of '$2'."
- else
- die "Branches need merging first."
- fi
- fi
-}
-
-#
-# gitflow_is_branch_merged_into()
-#
-# Checks whether branch $1 is succesfully merged into $2
-#
-gitflow_is_branch_merged_into() {
- local SUBJECT=$1
- local BASE=$2
- ALL_MERGES=$(git branch --contains $SUBJECT | sed 's/^[* ] //')
- has $BASE $ALL_MERGES
-}
-
# helper functions for common reuse
max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; }
diff --git a/git-flow-feature b/git-flow-feature
index 33dab30..f25ae7f 100644
--- a/git-flow-feature
+++ b/git-flow-feature
@@ -32,28 +32,33 @@
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
- FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
- if [ -z "$FEATURE_BRANCHES" ]; then
+ typeset feature_branches
+ typeset current_branch
+ typeset short_names
+ feature_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+ if [ -z "$feature_branches" ]; then
warn "No feature branches exist."
exit 0
fi
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ short_names=$(echo "$feature_branches" | sed "s ^$PREFIX g")
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
- SHORT_NAMES=$(echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
- width=0
- for branch in $SHORT_NAMES; do
- len=$(($(echo "$branch" | wc -c) - 1))
+ typeset -i width=0
+ typeset branch
+ for branch in $short_names; do
+ typeset -i len=${#branch}
width=$(max $width $len)
done
- width=$(($width + 3))
+ width=width+3
- for branch in $SHORT_NAMES; do
- fullname="$PREFIX$branch"
- base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
- develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
- branch_sha=$(git rev-parse "$fullname")
- if [ "$fullname" = "$CURRENT_BRANCH" ]; then
+ typeset branch
+ for branch in $short_names; do
+ typeset fullname="$PREFIX$branch"
+ typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
+ typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
+ typeset branch_sha=$(git rev-parse "$fullname")
+ if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
@@ -82,26 +87,27 @@
}
resolve_name_by_prefix() {
+ typeset matches
+ typeset -i num_matches
+
# first, check if there is a perfect match
if has "$LOCAL_BRANCHES" "$PREFIX$1"; then
echo "$1"
return 0
fi
- MATCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
- NUM_MATCHES=$(echo "$MATCHES" | wc -l)
- if [ -z "$MATCHES" ]; then
+ matches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
+ num_matches=$(echo "$matches" | wc -l)
+ if [ -z "$matches" ]; then
# no prefix match, so take it literally
echo "$1"
else
- if [ $NUM_MATCHES -eq 1 ]; then
- # sed arg looks a bit weird, but $PREFIX should not contain spaces,
- # so this one is safe
- echo "$MATCHES" | sed "s $PREFIX g"
+ if [ $num_matches -eq 1 ]; then
+ echo "${matches#$PREFIX}"
else
# multiple matches, cannot decide
warn "Multiple branches match for prefix '$1':"
- for match in $MATCHES; do
+ for match in $matches; do
warn "- $match"
done
die "Aborting. Use an unambiguous prefix."
@@ -127,11 +133,11 @@
}
expand_name_arg_prefix_or_current() {
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
if [ "$NAME" != "" ]; then
expand_name_arg_prefix
- elif [ "$CURRENT_BRANCH" != "" ]; then
- BRANCH="$CURRENT_BRANCH"
+ elif [ "$current_branch" != "" ]; then
+ BRANCH="$current_branch"
NAME=$(echo "$BRANCH" | sed "s?$PREFIX??g")
else
warn "The current HEAD is no feature branch."
@@ -364,8 +370,8 @@
BASE=$(git merge-base $DEVELOP_BRANCH $BRANCH)
git diff $BASE..$BRANCH
else
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
- if ! echo "$CURRENT_BRANCH" | grep -q "^$PREFIX"; then
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ if ! echo "$current_branch" | grep -q "^$PREFIX"; then
die "Not on a feature branch. Name one explicitly."
fi
@@ -383,7 +389,7 @@
gitflow_require_branch "$BRANCH"
git checkout -q "$BRANCH"
- OPTS=
+ typeset OPTS=
if flag interactive; then
OPTS="$OPTS -i"
fi
diff --git a/git-flow-hotfix b/git-flow-hotfix
index efc69a7..35fed5b 100644
--- a/git-flow-hotfix
+++ b/git-flow-hotfix
@@ -30,28 +30,33 @@
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
- HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
- if [ -z "$HOTFIX_BRANCHES" ]; then
+ typeset hotfix_branches
+ typeset current_branch
+ typeset short_names
+ hotfix_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+ if [ -z "$hotfix_branches" ]; then
warn "No hotfix branches exist."
exit 0
fi
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ short_names=$(echo "$hotfix_branches" | sed "s?^$PREFIX??g")
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
- SHORT_NAMES=$(echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
- width=0
- for branch in $SHORT_NAMES; do
- len=$(($(echo "$branch" | wc -c) - 1))
+ typeset -i width=0
+ typeset branch
+ for branch in $short_names; do
+ typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
done
- width=$(($width + 3))
+ width=width+3
- for branch in $SHORT_NAMES; do
- fullname="$PREFIX$branch"
- base=$(git merge-base "$fullname" "$MASTER_BRANCH")
- master_sha=$(git rev-parse "$MASTER_BRANCH")
- branch_sha=$(git rev-parse "$fullname")
- if [ "$fullname" = "$CURRENT_BRANCH" ]; then
+ typeset branch
+ for branch in $short_names; do
+ typeset fullname="$PREFIX$branch"
+ typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
+ typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
+ typeset branch_sha=$(git rev-parse "$fullname")
+ if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
@@ -61,7 +66,8 @@
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
else
- tagname=$(git name-rev --tags --no-undefined --name-only $base)
+ typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
+ typeset nicename
if [ "$tagname" != "" ]; then
nicename="$tagname"
else
diff --git a/git-flow-release b/git-flow-release
index b75891e..b23914e 100644
--- a/git-flow-release
+++ b/git-flow-release
@@ -41,28 +41,34 @@
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
- RELEASE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
- if [ -z "$RELEASE_BRANCHES" ]; then
+ typeset release_branches
+ typeset current_branch
+ typeset short_names
+ release_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+ if [ -z "$release_branches" ]; then
warn "No release branches exist."
exit 0
fi
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
- SHORT_NAMES=$(echo "$RELEASE_BRANCHES" | sed "s?^$PREFIX??g")
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ short_names=$(echo "$release_branches" | sed "s?^$PREFIX??g")
+
# determine column width first
- width=0
- for branch in $SHORT_NAMES; do
- len=$(($(echo "$branch" | wc -c) - 1))
+ typeset -i width=0
+ typeset branch
+ for branch in $short_names; do
+ typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
done
- width=$(($width + 3))
+ width=width+3
- for branch in $SHORT_NAMES; do
- fullname="$PREFIX$branch"
- base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
- develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
- branch_sha=$(git rev-parse "$fullname")
- if [ "$fullname" = "$CURRENT_BRANCH" ]; then
+ typeset branch
+ for branch in $short_names; do
+ typeset fullname="$PREFIX$branch"
+ typeset base=$(git merge-base "$fullname" "$DEVELOP_BRANCH")
+ typeset develop_sha=$(git rev-parse "$DEVELOP_BRANCH")
+ typeset branch_sha=$(git rev-parse "$fullname")
+ if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
@@ -72,7 +78,7 @@
if [ "$branch_sha" = "$develop_sha" ]; then
printf "(no commits yet)"
else
- nicename="$(git rev-parse --short $base)"
+ typeset nicename="$(git rev-parse --short $base)"
printf "(based on $nicename)"
fi
else
diff --git a/git-flow-support b/git-flow-support
index e334592..5dd07d8 100644
--- a/git-flow-support
+++ b/git-flow-support
@@ -32,28 +32,33 @@
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"
- SUPPORT_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
- if [ -z "$SUPPORT_BRANCHES" ]; then
+ typeset support_branches
+ typeset current_branch
+ typeset short_names
+ support_branches="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
+ if [ -z "$support_branches" ]; then
warn "No support branches exist."
exit 0
fi
+ current_branch=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
+ short_names=$(echo "$support_branches" | sed "s?^$PREFIX??g")
- CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
- SHORT_NAMES=$(echo "$SUPPORT_BRANCHES" | sed "s?^$PREFIX??g")
# determine column width first
- width=0
- for branch in $SHORT_NAMES; do
- len=$(($(echo "$branch" | wc -c) - 1))
+ typeset -i width=0
+ typeset branch
+ for branch in $short_names; do
+ typeset -i len=$(($(echo "$branch" | wc -c) - 1))
width=$(max $width $len)
done
- width=$(($width + 3))
+ width=width+3
- for branch in $SHORT_NAMES; do
- fullname="$PREFIX$branch"
- base=$(git merge-base "$fullname" "$MASTER_BRANCH")
- master_sha=$(git rev-parse "$MASTER_BRANCH")
- branch_sha=$(git rev-parse "$fullname")
- if [ "$fullname" = "$CURRENT_BRANCH" ]; then
+ typeset branch
+ for branch in $short_names; do
+ typeset fullname="$PREFIX$branch"
+ typeset base=$(git merge-base "$fullname" "$MASTER_BRANCH")
+ typeset master_sha=$(git rev-parse "$MASTER_BRANCH")
+ typeset branch_sha=$(git rev-parse "$fullname")
+ if [ "$fullname" = "$current_branch" ]; then
printf "* "
else
printf " "
@@ -63,7 +68,8 @@
if [ "$branch_sha" = "$master_sha" ]; then
printf "(no commits yet)"
else
- tagname=$(git name-rev --tags --no-undefined --name-only $base)
+ typeset tagname=$(git name-rev --tags --no-undefined --name-only $base)
+ typeset nicename
if [ "$tagname" != "" ]; then
nicename="$tagname"
else
diff --git a/gitflow-common b/gitflow-common
new file mode 100644
index 0000000..bcc6dbd
--- /dev/null
+++ b/gitflow-common
@@ -0,0 +1,147 @@
+#
+# git-flow -- A collection of Git extensions to provide high-level
+# repository operations for Vincent Driessen's branching model.
+#
+# Original blog post presenting this model is found at:
+# http://nvie.com/archives/323
+#
+# Feel free to contribute to this project at:
+# http://github.com/nvie/gitflow
+#
+# Copyright (c) 2010 by Vincent Driessen
+# Copyright (c) 2010 by Benedikt Böhm
+#
+
+# shell output
+warn() { echo "$@" >&2; }
+die() { warn "$@"; exit 1; }
+
+# set logic
+has() {
+ typeset item=$1; shift
+ echo " $@ " | grep -q " $item "
+}
+
+# basic math
+min() { [ "$1" -le "$2" ] && echo "$1" || echo "$2"; }
+max() { [ "$1" -ge "$2" ] && echo "$1" || echo "$2"; }
+
+# basic string matching
+startswith() { [ "$1" != "${1#$2}" ]; }
+endswith() { [ "$1" != "${1#$2}" ]; }
+
+# convenience functions for checking shFlags flags
+flag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -eq $FLAGS_TRUE ]; }
+noflag() { typeset FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
+
+#
+# Git specific common functionality
+#
+
+# get all available branches
+LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //')
+REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //')
+ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
+
+gitflow_test_clean_working_tree() {
+ if ! git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
+ return 1
+ elif ! git diff-index --cached --quiet --ignore-submodules HEAD --; then
+ return 2
+ else
+ return 0
+ fi
+}
+
+gitflow_require_clean_working_tree() {
+ gitflow_test_clean_working_tree
+ typeset -i result=$?
+ if [ $result -eq 1 ]; then
+ die "fatal: Working tree contains unstaged changes. Aborting."
+ fi
+ if [ $result -eq 2 ]; then
+ die "fatal: Index contains uncommited changes. Aborting."
+ fi
+}
+
+gitflow_require_local_branch() {
+ if ! has $1 $LOCAL_BRANCHES; then
+ die "fatal: Local branch '$1' does not exist and is required."
+ fi
+}
+
+gitflow_require_remote_branch() {
+ if ! has $1 $REMOTE_BRANCHES; then
+ die "Remote branch '$1' does not exist and is required."
+ fi
+}
+
+gitflow_require_branch() {
+ if ! has $1 $ALL_BRANCHES; then
+ die "Branch '$1' does not exist and is required."
+ fi
+}
+
+gitflow_require_branch_absent() {
+ if has $1 $ALL_BRANCHES; then
+ die "Branch '$1' already exists. Pick another name."
+ fi
+}
+
+#
+# gitflow_test_branches_equal()
+#
+# Tests whether branches and their "origin" counterparts have diverged and need
+# merging first. It returns error codes to provide more detail, like so:
+#
+# 0 Branch heads point to the same commit
+# 1 First given branch needs fast-forwarding
+# 2 Second given branch needs fast-forwarding
+# 3 Branch needs a real merge
+#
+gitflow_test_branches_equal() {
+ typeset commit1=$(git rev-parse "$1")
+ typeset commit2=$(git rev-parse "$2")
+ if [ "$commit1" != "$commit2" ]; then
+ typeset base=$(git merge-base "$commit1" "$commit2")
+ if [ "$commit1" = "$base" ]; then
+ return 1
+ elif [ "$commit2" = "$base" ]; then
+ return 2
+ else
+ return 3
+ fi
+ else
+ return 0
+ fi
+}
+
+gitflow_require_branches_equal() {
+ gitflow_require_local_branch "$1"
+ gitflow_require_remote_branch "$2"
+ gitflow_test_branches_equal "$1" "$2"
+ typeset -i status=$?
+ if [ $status -gt 0 ]; then
+ warn "Branches '$1' and '$2' have diverged."
+ if [ $status -eq 1 ]; then
+ die "And branch '$1' may be fast-forwarded."
+ elif [ $status -eq 2 ]; then
+ # Warn here, since there is no harm in being ahead
+ warn "And local branch '$1' is ahead of '$2'."
+ else
+ die "Branches need merging first."
+ fi
+ fi
+}
+
+#
+# gitflow_is_branch_merged_into()
+#
+# Checks whether branch $1 is succesfully merged into $2
+#
+gitflow_is_branch_merged_into() {
+ typeset subject=$1
+ typeset base=$2
+ typeset all_merges=$(git branch --contains $subject | sed 's/^[* ] //')
+ has $base $all_merges
+}
diff --git a/shFlags.sh b/gitflow-shFlags
similarity index 100%
rename from shFlags.sh
rename to gitflow-shFlags