Added an optional <base> argument to all start subactions.
The only exception to the rule is git-flow-support, which has an explicitly required <base> argument (since we cannot deduce a sane default name for base). Furthermore, these <base> arguments are checked to refer to commits on: - develop (for feature, release) - master (for hotfix, support) Removed any occurrences of optional <base> arguments in finish subactions. The finishing target branches are clearly defined by the model. The <base> argument will probably confuse users. If they want the power to merge those feature branches into *other* branches then develop, for example, they can still use the magical power of Git itself for that. Gitflow should not provide such support.
This commit is contained in:
parent
9277024410
commit
010252a8a9
5 changed files with 77 additions and 56 deletions
14
README.mdown
14
README.mdown
|
@ -58,22 +58,28 @@ Example uses:
|
||||||
git flow feature start <name> [<base>]
|
git flow feature start <name> [<base>]
|
||||||
git flow feature finish <name>
|
git flow feature finish <name>
|
||||||
|
|
||||||
(`base` is `develop` by default)
|
For feature branches, the `<base>` arg must be a commit on `develop`.
|
||||||
|
|
||||||
* To list/start/finish release branches, use:
|
* To list/start/finish release branches, use:
|
||||||
|
|
||||||
git flow release
|
git flow release
|
||||||
git flow release start <release>
|
git flow release start <release> [<base>]
|
||||||
git flow release finish <release>
|
git flow release finish <release>
|
||||||
|
|
||||||
|
For release branches, the `<base>` arg must be a commit on `develop`.
|
||||||
|
|
||||||
* To list/start/finish hotfix branches, use:
|
* To list/start/finish hotfix branches, use:
|
||||||
|
|
||||||
git flow hotfix
|
git flow hotfix
|
||||||
git flow hotfix start <release> [<base-release>]
|
git flow hotfix start <release> [<base>]
|
||||||
git flow hotfix finish <release>
|
git flow hotfix finish <release>
|
||||||
|
|
||||||
|
For hotfix branches, the `<base>` arg must be a commit on `master`.
|
||||||
|
|
||||||
* To list/start support branches, use:
|
* To list/start support branches, use:
|
||||||
|
|
||||||
git flow support
|
git flow support
|
||||||
git flow support start <release> [<base-release>]
|
git flow support start <release> <base>
|
||||||
|
|
||||||
|
For support branches, the `<base>` arg must be a commit on `master`.
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: git flow feature [list] [-v]"
|
echo "usage: git flow feature [list] [-v]"
|
||||||
echo " git flow feature start [-Fv] <name> [<base>]"
|
echo " git flow feature start [-Fv] <name> [<base>]"
|
||||||
echo " git flow feature finish [-rsFv] <name|nameprefix> [<base>]"
|
echo " git flow feature finish [-rsFv] <name|nameprefix>"
|
||||||
echo " git flow feature publish <name>"
|
echo " git flow feature publish <name>"
|
||||||
echo " git flow feature track <name>"
|
echo " git flow feature track <name>"
|
||||||
echo " git flow feature diff <name|nameprefix>"
|
echo " git flow feature diff <name|nameprefix>"
|
||||||
|
@ -148,7 +148,6 @@ parse_args() {
|
||||||
|
|
||||||
# read arguments into global variables
|
# read arguments into global variables
|
||||||
NAME="$1"
|
NAME="$1"
|
||||||
BASE="${2:-$DEVELOP_BRANCH}"
|
|
||||||
BRANCH=$PREFIX$NAME
|
BRANCH=$PREFIX$NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +155,7 @@ cmd_start() {
|
||||||
DEFINE_boolean fetch false 'fetch from origin before performing local operation' F
|
DEFINE_boolean fetch false 'fetch from origin before performing local operation' F
|
||||||
DEFINE_boolean force false 'force creation of feature branch (ignores dirty working tree)' f
|
DEFINE_boolean force false 'force creation of feature branch (ignores dirty working tree)' f
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
BASE="${2:-$DEVELOP_BRANCH}"
|
||||||
require_name
|
require_name
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
|
@ -248,24 +248,22 @@ cmd_finish() {
|
||||||
if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
|
if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
|
||||||
gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
|
gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
|
||||||
fi
|
fi
|
||||||
if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
||||||
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
|
||||||
fi
|
|
||||||
|
|
||||||
# if the user wants to rebase, do that first
|
# if the user wants to rebase, do that first
|
||||||
if flag rebase; then
|
if flag rebase; then
|
||||||
if ! git flow feature rebase "$NAME" "$BASE"; then
|
if ! git flow feature rebase "$NAME" "$DEVELOP_BRANCH"; then
|
||||||
warn "Finish was aborted due to conflicts during rebase."
|
warn "Finish was aborted due to conflicts during rebase."
|
||||||
warn "Please finish the rebase manually now."
|
warn "Please finish the rebase manually now."
|
||||||
warn "When finished, re-run:"
|
warn "When finished, re-run:"
|
||||||
warn " git flow feature finish '$NAME' '$BASE'"
|
warn " git flow feature finish '$NAME' '$DEVELOP_BRANCH'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# merge into BASE
|
# merge into BASE
|
||||||
git checkout $BASE
|
git checkout $DEVELOP_BRANCH
|
||||||
if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" -eq 1 ]; then
|
if [ "$(git rev-list -n2 $DEVELOP_BRANCH..$BRANCH | wc -l)" -eq 1 ]; then
|
||||||
git merge --ff $BRANCH
|
git merge --ff $BRANCH
|
||||||
else
|
else
|
||||||
git merge --no-ff $BRANCH
|
git merge --no-ff $BRANCH
|
||||||
|
@ -273,9 +271,9 @@ cmd_finish() {
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
# oops.. we have a merge conflict!
|
# oops.. we have a merge conflict!
|
||||||
# write the given $BASE to a temporary file (we need it later)
|
# write the given $DEVELOP_BRANCH to a temporary file (we need it later)
|
||||||
mkdir -p "$GIT_DIR/.gitflow"
|
mkdir -p "$GIT_DIR/.gitflow"
|
||||||
echo "$BASE" > "$GIT_DIR/.gitflow/MERGE_BASE"
|
echo "$DEVELOP_BRANCH" > "$GIT_DIR/.gitflow/MERGE_BASE"
|
||||||
echo
|
echo
|
||||||
echo "There were merge conflicts. To resolve the merge conflict manually, use:"
|
echo "There were merge conflicts. To resolve the merge conflict manually, use:"
|
||||||
echo " git mergetool"
|
echo " git mergetool"
|
||||||
|
@ -304,10 +302,10 @@ helper_finish_cleanup() {
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Summary of actions:"
|
echo "Summary of actions:"
|
||||||
echo "- The feature branch '$BRANCH' was merged into '$BASE'"
|
echo "- The feature branch '$BRANCH' was merged into '$DEVELOP_BRANCH'"
|
||||||
#echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
|
#echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
|
||||||
echo "- Feature branch '$BRANCH' has been removed"
|
echo "- Feature branch '$BRANCH' has been removed"
|
||||||
echo "- You are now on branch '$BASE'"
|
echo "- You are now on branch '$DEVELOP_BRANCH'"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,5 +378,5 @@ cmd_rebase() {
|
||||||
if flag interactive; then
|
if flag interactive; then
|
||||||
OPTS="$OPTS -i"
|
OPTS="$OPTS -i"
|
||||||
fi
|
fi
|
||||||
git rebase $OPTS "$BASE"
|
git rebase $OPTS "$DEVELOP_BRANCH"
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,7 @@ FLAG_FETCH=1
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: git flow hotfix [list] [-v]"
|
echo "usage: git flow hotfix [list] [-v]"
|
||||||
echo " git flow hotfix start <version> [<base>]"
|
echo " git flow hotfix start <version> [<base>]"
|
||||||
echo " git flow hotfix finish <version> [<base>]"
|
echo " git flow hotfix finish <version>"
|
||||||
# TODO
|
|
||||||
#echo ""
|
|
||||||
#echo "options:"
|
|
||||||
#echo "--option Explanation"
|
|
||||||
#echo ""
|
|
||||||
#echo "start-only options:"
|
|
||||||
#echo "--option Explanation"
|
|
||||||
#echo ""
|
|
||||||
#echo "finish-only options:"
|
|
||||||
#echo "--push Push to the origin repo when finished"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_default() {
|
cmd_default() {
|
||||||
|
@ -98,7 +88,6 @@ parse_args() {
|
||||||
|
|
||||||
# read arguments into global variables
|
# read arguments into global variables
|
||||||
VERSION="$1"
|
VERSION="$1"
|
||||||
BASE="${2:-$MASTER_BRANCH}"
|
|
||||||
BRANCH=$PREFIX$VERSION
|
BRANCH=$PREFIX$VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +99,19 @@ require_version_arg() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_base_is_on_master() {
|
||||||
|
if ! git branch --contains "$BASE" 2>/dev/null \
|
||||||
|
| sed 's/[* ] //g' \
|
||||||
|
| grep -q "^$MASTER_BRANCH\$"; then
|
||||||
|
die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cmd_start() {
|
cmd_start() {
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
BASE="${2:-$MASTER_BRANCH}"
|
||||||
|
require_version_arg
|
||||||
|
require_base_is_on_master
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
gitflow_require_clean_working_tree
|
gitflow_require_clean_working_tree
|
||||||
|
@ -134,12 +134,13 @@ cmd_start() {
|
||||||
echo "- Start committing your hot fixes"
|
echo "- Start committing your hot fixes"
|
||||||
echo "- When done, run:"
|
echo "- When done, run:"
|
||||||
echo
|
echo
|
||||||
echo " git flow finish hotfix '$HOTFIX_BRANCH'"
|
echo " git flow hotfix finish '$VERSION'"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_finish() {
|
cmd_finish() {
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
require_version_arg
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
gitflow_require_clean_working_tree
|
gitflow_require_clean_working_tree
|
||||||
|
@ -150,17 +151,14 @@ cmd_finish() {
|
||||||
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
|
gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
|
||||||
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
||||||
|
|
||||||
# merge into BASE
|
# merge into master
|
||||||
git checkout $BASE
|
git checkout $MASTER_BRANCH
|
||||||
git merge --no-ff $BRANCH
|
git merge --no-ff $BRANCH
|
||||||
git tag $VERSION_PREFIX$VERSION
|
git tag $VERSION_PREFIX$VERSION
|
||||||
|
|
||||||
# merge into develop if we fixed a master issue
|
# merge into develop if we fixed a master issue
|
||||||
# TODO: merge into support branch
|
git checkout $DEVELOP_BRANCH
|
||||||
if [ "$BASE" = "$MASTER_BRANCH" ]; then
|
git merge --no-ff $BRANCH
|
||||||
git checkout $DEVELOP_BRANCH
|
|
||||||
git merge --no-ff $BRANCH
|
|
||||||
fi
|
|
||||||
|
|
||||||
# delete branch
|
# delete branch
|
||||||
git branch -d $BRANCH
|
git branch -d $BRANCH
|
||||||
|
@ -171,11 +169,9 @@ cmd_finish() {
|
||||||
echo
|
echo
|
||||||
echo "Summary of actions:"
|
echo "Summary of actions:"
|
||||||
echo "- Latest objects have been fetched from '$ORIGIN'"
|
echo "- Latest objects have been fetched from '$ORIGIN'"
|
||||||
echo "- Hotfix branch has been merged into '$BASE'"
|
echo "- Hotfix branch has been merged into '$MASTER_BRANCH'"
|
||||||
echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
|
echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
|
||||||
if [ "$BASE" = "$MASTER_BRANCH" ]; then
|
echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
|
||||||
echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
|
|
||||||
fi
|
|
||||||
echo "- Hotfix branch '$BRANCH' has been deleted"
|
echo "- Hotfix branch '$BRANCH' has been deleted"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,9 +105,19 @@ require_version_arg() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_base_is_on_develop() {
|
||||||
|
if ! git branch --contains "$BASE" 2>/dev/null \
|
||||||
|
| sed 's/[* ] //g' \
|
||||||
|
| grep -q "^$DEVELOP_BRANCH\$"; then
|
||||||
|
die "fatal: Given base '$BASE' is not a valid commit on '$DEVELOP_BRANCH'."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cmd_start() {
|
cmd_start() {
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
BASE="${2:-$DEVELOP_BRANCH}"
|
||||||
require_version_arg
|
require_version_arg
|
||||||
|
require_base_is_on_develop
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
gitflow_require_clean_working_tree
|
gitflow_require_clean_working_tree
|
||||||
|
@ -118,11 +128,11 @@ cmd_start() {
|
||||||
gitflow_require_branch_absent $BRANCH
|
gitflow_require_branch_absent $BRANCH
|
||||||
|
|
||||||
# create branch
|
# create branch
|
||||||
git checkout -b $BRANCH $DEVELOP_BRANCH
|
git checkout -b $BRANCH $BASE
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Summary of actions:"
|
echo "Summary of actions:"
|
||||||
echo "- A new branch '$BRANCH' was created, based on '$DEVELOP_BRANCH'"
|
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
|
||||||
echo "- You are now on branch '$BRANCH'"
|
echo "- You are now on branch '$BRANCH'"
|
||||||
echo
|
echo
|
||||||
echo "Follow-up actions:"
|
echo "Follow-up actions:"
|
||||||
|
@ -130,7 +140,7 @@ cmd_start() {
|
||||||
echo "- Start committing last-minute fixes in preparing your release"
|
echo "- Start committing last-minute fixes in preparing your release"
|
||||||
echo "- When done, run:"
|
echo "- When done, run:"
|
||||||
echo
|
echo
|
||||||
echo " git flow finish release '$VERSION'"
|
echo " git flow release finish '$VERSION'"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ warn "note: DO NOT use it in a production situation."
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: git flow support [list] [-v]"
|
echo "usage: git flow support [list] [-v]"
|
||||||
echo " git flow support start <version> [<base>]"
|
echo " git flow support start <version> <base>"
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd_default() {
|
cmd_default() {
|
||||||
|
@ -90,7 +90,7 @@ parse_args() {
|
||||||
|
|
||||||
# read arguments into global variables
|
# read arguments into global variables
|
||||||
VERSION="$1"
|
VERSION="$1"
|
||||||
BASE="${2:-${VERSION_PREFIX}${VERSION}}"
|
BASE="$2"
|
||||||
BRANCH=$PREFIX$VERSION
|
BRANCH=$PREFIX$VERSION
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,9 +102,27 @@ require_version_arg() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require_base_arg() {
|
||||||
|
if [ "$BASE" = "" ]; then
|
||||||
|
warn "Missing argument <base>"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
require_base_is_on_master() {
|
||||||
|
if ! git branch --contains "$BASE" 2>/dev/null \
|
||||||
|
| sed 's/[* ] //g' \
|
||||||
|
| grep -q "^$MASTER_BRANCH\$"; then
|
||||||
|
die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
cmd_start() {
|
cmd_start() {
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
require_version_arg
|
require_version_arg
|
||||||
|
require_base_arg
|
||||||
|
require_base_is_on_master
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
gitflow_require_clean_working_tree
|
gitflow_require_clean_working_tree
|
||||||
|
@ -113,21 +131,14 @@ cmd_start() {
|
||||||
if [ $FLAG_FETCH -eq 1 ]; then
|
if [ $FLAG_FETCH -eq 1 ]; then
|
||||||
git fetch -q $ORIGIN $BASE
|
git fetch -q $ORIGIN $BASE
|
||||||
fi
|
fi
|
||||||
|
gitflow_require_branch_absent $BRANCH
|
||||||
|
|
||||||
# create branch
|
# create branch
|
||||||
git checkout -b "$BRANCH" "$BASE"
|
git checkout -b "$BRANCH" "$BASE"
|
||||||
|
|
||||||
# publish branch
|
|
||||||
#git push $ORIGIN $BRANCH:refs/heads/$BRANCH
|
|
||||||
|
|
||||||
git config branch.$BRANCH.remote $ORIGIN
|
|
||||||
git config branch.$BRANCH.merge refs/heads/$BRANCH
|
|
||||||
git checkout $BRANCH
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "Summary of actions:"
|
echo "Summary of actions:"
|
||||||
echo "- A new remote branch '$BRANCH' was created, based on '$BASE'"
|
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
|
||||||
echo "- A new tracking branch '$BRANCH' was created"
|
|
||||||
echo "- You are now on branch '$BRANCH'"
|
echo "- You are now on branch '$BRANCH'"
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue