Tidy up:
- Lower-cased all local variable names
- Explicitly typeset all local variable names, to prevent issues with
setting/overriding variables in the global namespace.
- Explicitly typed integer types as integer (typeset -i) to enable simpler
arithmetic calculations on them.
diff --git a/gitflow-common b/gitflow-common
index 0cc6802..bcc6dbd 100644
--- a/gitflow-common
+++ b/gitflow-common
@@ -18,7 +18,7 @@
# set logic
has() {
- local item=$1; shift
+ typeset item=$1; shift
echo " $@ " | grep -q " $item "
}
@@ -31,8 +31,8 @@
endswith() { [ "$1" != "${1#$2}" ]; }
# convenience functions for checking shFlags flags
-flag() { eval FLAG='$FLAGS_'$1; [ $FLAG -eq $FLAGS_TRUE ]; }
-noflag() { eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
+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
@@ -55,7 +55,7 @@
gitflow_require_clean_working_tree() {
gitflow_test_clean_working_tree
- result=$?
+ typeset -i result=$?
if [ $result -eq 1 ]; then
die "fatal: Working tree contains unstaged changes. Aborting."
fi
@@ -100,10 +100,10 @@
# 3 Branch needs a real merge
#
gitflow_test_branches_equal() {
- commit1=$(git rev-parse "$1")
- commit2=$(git rev-parse "$2")
+ typeset commit1=$(git rev-parse "$1")
+ typeset commit2=$(git rev-parse "$2")
if [ "$commit1" != "$commit2" ]; then
- base=$(git merge-base "$commit1" "$commit2")
+ typeset base=$(git merge-base "$commit1" "$commit2")
if [ "$commit1" = "$base" ]; then
return 1
elif [ "$commit2" = "$base" ]; then
@@ -120,7 +120,7 @@
gitflow_require_local_branch "$1"
gitflow_require_remote_branch "$2"
gitflow_test_branches_equal "$1" "$2"
- status=$?
+ typeset -i status=$?
if [ $status -gt 0 ]; then
warn "Branches '$1' and '$2' have diverged."
if [ $status -eq 1 ]; then
@@ -140,9 +140,8 @@
# 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
+ typeset subject=$1
+ typeset base=$2
+ typeset all_merges=$(git branch --contains $subject | sed 's/^[* ] //')
+ has $base $all_merges
}
-