Commit 21c7aa9c authored by Vincent Driessen's avatar Vincent Driessen

Don't store remote and local branch names in shell variables, but query

them live using git commands instead. This avoids git commands being
issued by subcommands that do not necessarily require an existing Git repo
to be initialized (i.e. git-flow init).
parent b3e89fe5
......@@ -35,7 +35,7 @@ cmd_list() {
local feature_branches
local current_branch
local short_names
feature_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
feature_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
if [ -z "$feature_branches" ]; then
warn "No feature branches exist."
exit 0
......@@ -231,7 +231,7 @@ cmd_finish() {
git fetch -q "$ORIGIN" "$BRANCH"
fi
if has "$ORIGIN/$BRANCH" "$REMOTE_BRANCHES"; then
if has "$ORIGIN/$BRANCH" "$(gitflow_remote_branches)"; then
gitflow_require_branches_equal "$BRANCH" "$ORIGIN/$BRANCH"
fi
gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH"
......
......@@ -32,7 +32,7 @@ cmd_list() {
local hotfix_branches
local current_branch
local short_names
hotfix_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
hotfix_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
if [ -z "$hotfix_branches" ]; then
warn "No hotfix branches exist."
exit 0
......@@ -113,7 +113,7 @@ require_base_is_on_master() {
}
require_no_existing_hotfix_branches() {
local hotfix_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
local hotfix_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
local first_branch=$(echo ${hotfix_branches} | head -n1)
first_branch=${first_branch#$PREFIX}
[ -z "$hotfix_branches" ] || \
......
......@@ -43,7 +43,7 @@ cmd_list() {
local release_branches
local current_branch
local short_names
release_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
release_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
if [ -z "$release_branches" ]; then
warn "No release branches exist."
exit 0
......@@ -119,7 +119,7 @@ require_base_is_on_develop() {
}
require_no_existing_release_branches() {
local release_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
local release_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
local first_branch=$(echo ${release_branches} | head -n1)
first_branch=${first_branch#$PREFIX}
[ -z "$release_branches" ] || \
......
......@@ -34,7 +34,7 @@ cmd_list() {
local support_branches
local current_branch
local short_names
support_branches=$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")
support_branches=$(echo "$(gitflow_local_branches)" | grep "^$PREFIX")
if [ -z "$support_branches" ]; then
warn "No support branches exist."
exit 0
......
......@@ -39,10 +39,10 @@ noflag() { local FLAG; eval FLAG='$FLAGS_'$1; [ $FLAG -ne $FLAGS_TRUE ]; }
#
# get all available branches
LOCAL_BRANCHES=$(git branch | sed 's/^[* ] //')
REMOTE_BRANCHES=$(git branch -r | sed 's/^[* ] //')
ALL_BRANCHES="$LOCAL_BRANCHES $REMOTE_BRANCHES"
ALL_TAGS=$(git tag)
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_tags() { git tag; }
#
# resolve_nameprefix
......@@ -51,8 +51,8 @@ ALL_TAGS=$(git tag)
# $1 = name prefix to resolve
# $2 = branch prefix to use
#
# Searches branch names from LOCAL_BRANCHES to look for a unique branch
# name whose name starts with the given name prefix.
# Searches branch names from gitflow_local_branches() to look for a unique
# branch name whose name starts with the given name prefix.
#
# There are multiple exit codes possible:
# 0: The unambiguous full name of the branch is written to stdout
......@@ -67,12 +67,12 @@ resolve_nameprefix() {
local num_matches
# first, check if there is a perfect match
if has "$LOCAL_BRANCHES" "$prefix$name"; then
if has "$(gitflow_local_branches)" "$prefix$name"; then
echo "$name"
return 0
fi
matches=$(echo "$LOCAL_BRANCHES" | grep "^$prefix$name")
matches=$(echo "$(gitflow_local_branches)" | grep "^$prefix$name")
num_matches=$(echo "$matches" | wc -l)
if [ -z "$matches" ]; then
# no prefix match, so take it literally
......@@ -119,37 +119,37 @@ gitflow_require_clean_working_tree() {
}
gitflow_require_local_branch() {
if ! has $1 $LOCAL_BRANCHES; then
if ! has $1 $(gitflow_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
if ! has $1 $(gitflow_remote_branches); then
die "Remote branch '$1' does not exist and is required."
fi
}
gitflow_require_branch() {
if ! has $1 $ALL_BRANCHES; then
if ! has $1 $(gitflow_all_branches); then
die "Branch '$1' does not exist and is required."
fi
}
gitflow_require_branch_absent() {
if has $1 $ALL_BRANCHES; then
if has $1 $(gitflow_all_branches); then
die "Branch '$1' already exists. Pick another name."
fi
}
gitflow_require_tag_absent() {
if has $1 $ALL_TAGS; then
if has $1 $(gitflow_all_tags); then
die "Tag '$1' already exists. Pick another name."
fi
}
gitflow_tag_exists() {
has $1 $ALL_TAGS
has $1 $(gitflow_all_tags)
}
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment