Skip to content

Commit

Permalink
Fix: Of course, in sh, true=0 and false=1. In order to never mess thi…
Browse files Browse the repository at this point in the history
…s up

again, the convenience functions flag() and noflag() have been used and
all occurrences of 0 and 1 are replaces by true and false. This makes it
safe (and more readable!) to test for active/inactive flags.

Also specify $FLAGS_PARENT explicitly, to avoid having the generated usage
texts by shFlags mention the full Unix path to $0, but instead use the
more recognizable varient 'git flow feature'.
  • Loading branch information
nvie committed Feb 2, 2010
1 parent 1db658f commit 4417492
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions git-flow
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ main() {

# use the shFlags project to parse the command line arguments
. "$GITFLOW_DIR/shFlags.sh"
FLAGS_PARENT="git flow"
#DEFINE_boolean quiet 0 'run without output' q
#DEFINE_boolean verbose 0 'run verbose (more output)' v
FLAGS "$@" || exit $?
Expand All @@ -79,6 +80,7 @@ main() {

# run command
. "$GITFLOW_DIR/git-flow-$SUBCOMMAND"
FLAGS_PARENT="git flow $SUBCOMMAND"

# test if the first argument is a flag (i.e. starts with '-')
# in that case, we interpret this arg as a flag for the default
Expand Down Expand Up @@ -200,4 +202,8 @@ gitflow_is_branch_merged_into() {
has $BASE $ALL_MERGES
}

# convenience functions for checking whether flags have been set or not
flag() { eval FLAG=\$FLAGS_$1; [ $FLAG -eq $FLAGS_TRUE ]; }
noflag() { eval FLAG=\$FLAGS_$1; [ $FLAG -ne $FLAGS_TRUE ]; }

main "$@"
24 changes: 12 additions & 12 deletions git-flow-feature
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cmd_default() {
max() { if [ "$1" -gt "$2" ]; then echo "$1"; else echo "$2"; fi; }

cmd_list() {
DEFINE_boolean verbose 0 'verbose (more) output' v
DEFINE_boolean verbose false 'verbose (more) output' v
parse_args "$@"

FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
Expand Down Expand Up @@ -60,7 +60,7 @@ cmd_list() {
else
printf " "
fi
if [ $FLAGS_verbose -eq 1 ]; then
if flag verbose; then
printf "%-${width}s" "$branch"
if [ "$branch_sha" = "$develop_sha" ]; then
printf "(no commits yet)"
Expand Down Expand Up @@ -155,7 +155,7 @@ parse_args() {
}

cmd_start() {
DEFINE_boolean fetch 0 'fetch from origin before performing local operation' F
DEFINE_boolean fetch false 'fetch from origin before performing local operation' F
parse_args "$@"
require_name

Expand All @@ -164,7 +164,7 @@ cmd_start() {
gitflow_require_branch_absent $BRANCH

# update the local repo with remote changes, if asked
if [ $FLAGS_fetch -eq 1 ]; then
if flag fetch; then
git fetch -q $ORIGIN $DEVELOP_BRANCH
fi

Expand All @@ -185,9 +185,9 @@ cmd_start() {
}

cmd_finish() {
DEFINE_boolean fetch 0 'fetch from origin before performing local operation' F
DEFINE_boolean rebase 0 'rebase instead of merge' r
DEFINE_boolean squash 0 'squash all commits when rebasing (implies --rebase)' s
DEFINE_boolean fetch false 'fetch from origin before performing local operation' F
DEFINE_boolean rebase false 'rebase instead of merge' r
DEFINE_boolean squash false 'squash all commits when rebasing (implies --rebase)' s
parse_args "$@"
expand_name_arg_prefix

Expand Down Expand Up @@ -238,7 +238,7 @@ cmd_finish() {
gitflow_require_clean_working_tree

# update local repo with remote changes first, if asked
if [ $FLAGS_fetch -eq 1 ]; then
if flag fetch; then
git fetch -q $ORIGIN $BRANCH
fi

Expand All @@ -250,7 +250,7 @@ cmd_finish() {
fi

# if the user wants to rebase, do that first
if [ $FLAGS_rebase -eq 1 ]; then
if flag rebase; then
if ! git flow feature rebase "$NAME" "$BASE"; then
warn "Finish was aborted due to conflicts during rebase."
warn "Please finish the rebase manually now."
Expand Down Expand Up @@ -294,7 +294,7 @@ helper_finish_cleanup() {
gitflow_require_clean_working_tree

# delete branch
if [ $FLAGS_fetch -eq 1 ]; then
if flag fetch; then
git push $ORIGIN :refs/heads/$BRANCH
fi
git branch -d $BRANCH
Expand Down Expand Up @@ -365,7 +365,7 @@ cmd_diff() {
}

cmd_rebase() {
DEFINE_boolean interactive 0 'do an interactive rebase' i
DEFINE_boolean interactive false 'do an interactive rebase' i
parse_args "$@"
expand_name_arg_prefix_or_current
warn "Will try to rebase '$NAME'..."
Expand All @@ -374,7 +374,7 @@ cmd_rebase() {

git checkout -q "$BRANCH"
OPTS=
if [ $FLAGS_interactive -eq 1 ]; then
if flag interactive; then
OPTS="$OPTS -i"
fi
git rebase $OPTS "$BASE"
Expand Down

0 comments on commit 4417492

Please sign in to comment.