2010-01-26 11:39:36 +00:00
|
|
|
#
|
|
|
|
# gitflow -- A collection of Git wrapper scripts to provide high-level
|
|
|
|
# repository operations for Vincent Driessen's branching model:
|
|
|
|
#
|
|
|
|
# Original blog post presenting this model is found at:
|
|
|
|
# http://nvie.com/archives/323
|
|
|
|
#
|
|
|
|
# Feel free to contribute to this project at:
|
|
|
|
# http://github.com/nvie/gitflow
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 by Vincent Driessen
|
|
|
|
# Copyright (c) 2010 by Benedikt Böhm
|
|
|
|
#
|
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "usage: git flow start feature <name> [<base>]"
|
|
|
|
echo " git flow finish feature <name> [<base>]"
|
|
|
|
echo " git flow publish feature <name>"
|
|
|
|
echo " git flow track feature <name>"
|
|
|
|
# TODO
|
|
|
|
#echo ""
|
|
|
|
#echo "options:"
|
|
|
|
#echo "--option Explanation"
|
|
|
|
#echo ""
|
|
|
|
#echo "start-only options:"
|
|
|
|
#echo "--option Explanation"
|
|
|
|
#echo ""
|
|
|
|
#echo "finish-only options:"
|
|
|
|
#echo "--rebase Rebases the feature branch on top of develop, instead of merging"
|
|
|
|
#echo "--squash Squashes all commits of the feature branch into a single commit"
|
|
|
|
#echo " on develop"
|
|
|
|
#echo "--push Push to the origin repo when finished"
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args() {
|
|
|
|
NAME="$1"
|
2010-01-26 11:59:27 +00:00
|
|
|
BASE="${2:-$DEVELOP_BRANCH}"
|
2010-01-26 11:39:36 +00:00
|
|
|
if [ "$NAME" = "" ]; then
|
|
|
|
echo "Missing argument <name>."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-01-26 12:09:32 +00:00
|
|
|
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
|
|
|
|
BRANCH=$PREFIX$NAME
|
2010-01-26 11:39:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd_help() {
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_start() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
# sanity checks
|
|
|
|
gitflow_check_clean_working_tree
|
|
|
|
gitflow_require_branch_absent $BRANCH
|
2010-01-26 11:59:27 +00:00
|
|
|
if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN $DEVELOP_BRANCH
|
2010-01-26 12:05:05 +00:00
|
|
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# create branch
|
|
|
|
git checkout -b $BRANCH $BASE
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Summary of actions:"
|
|
|
|
echo "- A new branch '$BRANCH' was created, based on '$BASE'"
|
|
|
|
echo "- You are now on branch '$BRANCH'"
|
|
|
|
echo ""
|
|
|
|
echo "Now, start committing on your feature. When done, use:"
|
|
|
|
echo ""
|
|
|
|
echo " git flow finish feature $NAME"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_finish() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
# sanity checks
|
|
|
|
gitflow_check_clean_working_tree
|
|
|
|
gitflow_require_branch $BRANCH
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN
|
2010-01-26 12:05:05 +00:00
|
|
|
if has $ORIGIN/$BRANCH $REMOTE_BRANCHES; then
|
|
|
|
gitflow_require_branches_equal $BRANCH $ORIGIN/$BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
fi
|
2010-01-26 11:59:27 +00:00
|
|
|
if [ "$BASE" = "$DEVELOP_BRANCH" ]; then
|
2010-01-26 12:05:05 +00:00
|
|
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# merge into BASE
|
|
|
|
git checkout $BASE
|
|
|
|
if [ "$(git rev-list -n2 $BASE..$BRANCH | wc -l)" = "1" ]; then
|
|
|
|
git merge --ff $BRANCH
|
|
|
|
else
|
|
|
|
git merge --no-ff $BRANCH
|
|
|
|
fi
|
|
|
|
|
|
|
|
# delete branch
|
|
|
|
# TODO: How do we handle merge conflicts here??
|
2010-01-26 12:05:05 +00:00
|
|
|
git push $ORIGIN :refs/heads/$BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
git branch -d $BRANCH
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Summary of actions:"
|
|
|
|
echo "- The feature branch '$BRANCH' was merged into '$BASE'"
|
|
|
|
#echo "- Merge conflicts were resolved" # TODO: Add this line when it's supported
|
|
|
|
echo "- Feature branch '$BRANCH' has been removed"
|
|
|
|
echo "- You are now on branch '$BASE'"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_publish() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
# sanity checks
|
|
|
|
gitflow_check_clean_working_tree
|
|
|
|
gitflow_require_branch $BRANCH
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN
|
2010-01-26 12:05:05 +00:00
|
|
|
gitflow_require_branch_absent $ORIGIN/$BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
# create remote branch
|
2010-01-26 12:05:05 +00:00
|
|
|
git push $ORIGIN $BRANCH:refs/heads/$BRANCH
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
# configure remote tracking
|
2010-01-26 12:05:05 +00:00
|
|
|
git config branch.$BRANCH.remote $ORIGIN
|
2010-01-26 11:39:36 +00:00
|
|
|
git config branch.$BRANCH.merge refs/heads/$BRANCH
|
|
|
|
git checkout $BRANCH
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Summary of actions:"
|
|
|
|
echo "- A new remote branch '$BRANCH' was created"
|
|
|
|
echo "- The local branch '$BRANCH' was configured to track the remote branch"
|
|
|
|
echo "- You are now on branch '$BRANCH'"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_track() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
# sanity checks
|
|
|
|
gitflow_check_clean_working_tree
|
|
|
|
gitflow_require_branch_absent $BRANCH
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN
|
2010-01-26 12:05:05 +00:00
|
|
|
gitflow_require_branch $ORIGIN/$BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
# create tracking branch
|
2010-01-26 12:05:05 +00:00
|
|
|
git checkout -b $BRANCH $ORIGIN/$BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "Summary of actions:"
|
|
|
|
echo "- A new remote tracking branch '$BRANCH' was created"
|
|
|
|
echo "- You are now on branch '$BRANCH'"
|
|
|
|
echo
|
|
|
|
}
|