Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitflow
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tools
gitflow
Commits
1b819236
Commit
1b819236
authored
Feb 01, 2010
by
Vincent Driessen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shFlags to parse flags given to main and subcommands.
Implement the flags for each of the 'feature' subcommands.
parent
ea58d0f1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
40 deletions
+51
-40
git-flow
git-flow
+7
-6
git-flow-feature
git-flow-feature
+44
-34
No files found.
git-flow
View file @
1b819236
...
@@ -80,12 +80,13 @@ main() {
...
@@ -80,12 +80,13 @@ main() {
# run command
# run command
.
"
$GITFLOW_DIR
/git-flow-
$SUBCOMMAND
"
.
"
$GITFLOW_DIR
/git-flow-
$SUBCOMMAND
"
#
# test if the first argument is a flag (i.e. starts with '-')
# TODO: How to handle 'git flow feature --verbose'
# in that case, we interpret this arg as a flag for the default
# instead of 'git flow feature list --verbose'
# command
# "--verbose" is not a subcommand!
SUBACTION
=
"default"
#
if
[
"
$1
"
!=
""
]
&&
!
echo
"
$1
"
|
grep
-q
"^-"
;
then
SUBACTION
=
"
${
1
:-
default
}
"
;
shift
SUBACTION
=
"
$1
"
;
shift
fi
if
!
typeset
-f
cmd_
$SUBACTION
2>&1
>
/dev/null
;
then
if
!
typeset
-f
cmd_
$SUBACTION
2>&1
>
/dev/null
;
then
warn
"Unknown subcommand: '
$1
'"
warn
"Unknown subcommand: '
$1
'"
usage
usage
...
...
git-flow-feature
View file @
1b819236
...
@@ -13,7 +13,6 @@
...
@@ -13,7 +13,6 @@
#
#
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
FLAG_FETCH=0
usage() {
usage() {
echo "usage: git flow feature [list]"
echo "usage: git flow feature [list]"
...
@@ -42,6 +41,9 @@ cmd_default() {
...
@@ -42,6 +41,9 @@ cmd_default() {
}
}
cmd_list() {
cmd_list() {
DEFINE_boolean verbose 0 'verbose (more) output' v
parse_args "$@"
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
if [ -z "$FEATURE_BRANCHES" ]; then
if [ -z "$FEATURE_BRANCHES" ]; then
warn "No feature branches exist."
warn "No feature branches exist."
...
@@ -64,13 +66,14 @@ resolve_name_by_prefix() {
...
@@ -64,13 +66,14 @@ resolve_name_by_prefix() {
MATCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
MATCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX$1")"
NUM_MATCHES=$(echo "$MATCHES" | wc -l)
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
if [ $NUM_MATCHES -eq 1 ]; then
# sed arg looks a bit weird, but $PREFIX should not contain spaces,
# sed arg looks a bit weird, but $PREFIX should not contain spaces,
# so this one is safe
# so this one is safe
echo "$MATCHES" | sed "s $PREFIX g"
echo "$MATCHES" | sed "s $PREFIX g"
elif [ $NUM_MATCHES -eq 0 ]; then
# no prefix match, so take it literally
echo "$1"
else
else
# multiple matches, cannot decide
# multiple matches, cannot decide
warn "Multiple branches match for prefix '$1':"
warn "Multiple branches match for prefix '$1':"
...
@@ -79,48 +82,47 @@ resolve_name_by_prefix() {
...
@@ -79,48 +82,47 @@ resolve_name_by_prefix() {
done
done
die "Aborting. Use an unambiguous prefix."
die "Aborting. Use an unambiguous prefix."
fi
fi
}
get_name_by_prefix() {
NAME=$(resolve_name_by_prefix "$1")
if [ -z "$NAME" ]; then
exit 1
fi
fi
}
}
parse_args_common() {
require_name() {
# TODO: When we have a nice structured way of parsing flags with getopt,
# implement the following flags:
# --fetch, to set FLAG_FETCH=1
# --no-fetch, to set FLAG_FETCH=0
BASE="${2:-$DEVELOP_BRANCH}"
if [ "$NAME" = "" ]; then
if [ "$NAME" = "" ]; then
echo "Missing argument <name>
.
"
echo "Missing argument <name>"
usage
usage
exit 1
exit 1
fi
fi
BRANCH=$PREFIX$NAME
}
}
parse_args_with_name_prefix() {
expand_name_arg_prefix() {
get_name_by_prefix "$1"
require_name
parse_args_common
NAME=$(resolve_name_by_prefix "$NAME")
if echo "$NAME" | grep -q "^[ \t\n\r]+$"; then
exit 1
fi
BRANCH=$PREFIX$NAME
}
}
parse_args() {
parse_args() {
# parse options
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
# read arguments into global variables
NAME="$1"
NAME="$1"
parse_args_common
BASE="${2:-$DEVELOP_BRANCH}"
}
}
cmd_start() {
cmd_start() {
DEFINE_boolean fetch 0 'fetch from origin before performing local operation' F
parse_args "$@"
parse_args "$@"
require_name
# sanity checks
# sanity checks
gitflow_require_clean_working_tree
gitflow_require_clean_working_tree
gitflow_require_branch_absent $BRANCH
gitflow_require_branch_absent $BRANCH
# update the local repo with remote changes, if asked
# update the local repo with remote changes, if asked
if [ $FLAG
_FETCH
-eq 1 ]; then
if [ $FLAG
S_fetch
-eq 1 ]; then
git fetch -q $ORIGIN $DEVELOP_BRANCH
git fetch -q $ORIGIN $DEVELOP_BRANCH
fi
fi
...
@@ -141,7 +143,11 @@ cmd_start() {
...
@@ -141,7 +143,11 @@ cmd_start() {
}
}
cmd_finish() {
cmd_finish() {
parse_args_with_name_prefix "$@"
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
parse_args "$@"
expand_name_arg_prefix
# sanity checks
# sanity checks
gitflow_require_branch $BRANCH
gitflow_require_branch $BRANCH
...
@@ -190,7 +196,7 @@ cmd_finish() {
...
@@ -190,7 +196,7 @@ cmd_finish() {
gitflow_require_clean_working_tree
gitflow_require_clean_working_tree
# update local repo with remote changes first, if asked
# update local repo with remote changes first, if asked
if [ $FLAG
_FETCH
-eq 1 ]; then
if [ $FLAG
S_fetch
-eq 1 ]; then
git fetch -q $ORIGIN $BRANCH
git fetch -q $ORIGIN $BRANCH
fi
fi
...
@@ -249,6 +255,7 @@ helper_finish_cleanup() {
...
@@ -249,6 +255,7 @@ helper_finish_cleanup() {
cmd_publish() {
cmd_publish() {
parse_args "$@"
parse_args "$@"
expand_name_arg_prefix
# sanity checks
# sanity checks
gitflow_require_clean_working_tree
gitflow_require_clean_working_tree
...
@@ -275,6 +282,7 @@ cmd_publish() {
...
@@ -275,6 +282,7 @@ cmd_publish() {
cmd_track() {
cmd_track() {
parse_args "$@"
parse_args "$@"
require_name
# sanity checks
# sanity checks
gitflow_require_clean_working_tree
gitflow_require_clean_working_tree
...
@@ -293,7 +301,9 @@ cmd_track() {
...
@@ -293,7 +301,9 @@ cmd_track() {
}
}
cmd_diff() {
cmd_diff() {
parse_args_with_name_prefix "$@"
parse_args "$@"
expand_name_arg_prefix
# TODO: if this feature has been based on a non-develop branch, we really
# TODO: if this feature has been based on a non-develop branch, we really
# should not be comparing to $DEVELOP. How to deal with this?
# should not be comparing to $DEVELOP. How to deal with this?
git diff $DEVELOP_BRANCH..$BRANCH
git diff $DEVELOP_BRANCH..$BRANCH
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment