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.
This commit is contained in:
parent
c3607ac2e8
commit
27592dd732
5 changed files with 109 additions and 86 deletions
|
@ -32,28 +32,33 @@ cmd_list() {
|
|||
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 @@ cmd_help() {
|
|||
}
|
||||
|
||||
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() {
|
|||
}
|
||||
|
||||
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 @@ cmd_diff() {
|
|||
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 @@ cmd_rebase() {
|
|||
gitflow_require_branch "$BRANCH"
|
||||
|
||||
git checkout -q "$BRANCH"
|
||||
OPTS=
|
||||
typeset OPTS=
|
||||
if flag interactive; then
|
||||
OPTS="$OPTS -i"
|
||||
fi
|
||||
|
|
|
@ -30,28 +30,33 @@ cmd_list() {
|
|||
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 @@ cmd_list() {
|
|||
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
|
||||
|
|
|
@ -41,28 +41,34 @@ cmd_list() {
|
|||
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 @@ cmd_list() {
|
|||
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
|
||||
|
|
|
@ -32,28 +32,33 @@ cmd_list() {
|
|||
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 @@ cmd_list() {
|
|||
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
|
||||
|
|
|
@ -18,7 +18,7 @@ die() { warn "$@"; exit 1; }
|
|||
|
||||
# set logic
|
||||
has() {
|
||||
local item=$1; shift
|
||||
typeset item=$1; shift
|
||||
echo " $@ " | grep -q " $item "
|
||||
}
|
||||
|
||||
|
@ -31,8 +31,8 @@ startswith() { [ "$1" != "${1#$2}" ]; }
|
|||
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_test_clean_working_tree() {
|
|||
|
||||
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 @@ gitflow_require_branch_absent() {
|
|||
# 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_branches_equal() {
|
|||
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 @@ gitflow_require_branches_equal() {
|
|||
# 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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue