Change implementation of gitflow_all_branches() to get its result directly from
git branch.
Added gitflow_branch_exists() function for testing existence.
Let gitflow_test_branches_equal() return with exit code 4 in case of the two
branches having no common ancestor.
diff --git a/gitflow-common b/gitflow-common
index 2ff3036..5b2a4f6 100644
--- a/gitflow-common
+++ b/gitflow-common
@@ -41,7 +41,7 @@
# get all available branches
gitflow_local_branches() { git branch | sed 's/^[* ] //'; }
gitflow_remote_branches() { git branch -r | sed 's/^[* ] //'; }
-gitflow_all_branches() { gitflow_local_branches; gitflow_remote_branches; }
+gitflow_all_branches() { git branch -a | sed 's/^[* ] //'; }
gitflow_all_tags() { git tag; }
# loading settings that can be overridden using git config
@@ -133,6 +133,14 @@
fi
}
+gitflow_branch_exists() {
+ has $1 $(gitflow_all_branches)
+}
+
+gitflow_tag_exists() {
+ has $1 $(gitflow_all_tags)
+}
+
gitflow_require_local_branch() {
if ! has $1 $(gitflow_local_branches); then
die "fatal: Local branch '$1' does not exist and is required."
@@ -163,10 +171,6 @@
fi
}
-gitflow_tag_exists() {
- has $1 $(gitflow_all_tags)
-}
-
#
# gitflow_test_branches_equal()
#
@@ -177,13 +181,16 @@
# 1 First given branch needs fast-forwarding
# 2 Second given branch needs fast-forwarding
# 3 Branch needs a real merge
+# 4 There is no merge base, i.e. the branches have no common ancestors
#
gitflow_test_branches_equal() {
local commit1=$(git rev-parse "$1")
local commit2=$(git rev-parse "$2")
if [ "$commit1" != "$commit2" ]; then
local base=$(git merge-base "$commit1" "$commit2")
- if [ "$commit1" = "$base" ]; then
+ if [ $? -ne 0 ]; then
+ return 4
+ elif [ "$commit1" = "$base" ]; then
return 1
elif [ "$commit2" = "$base" ]; then
return 2