2010-01-26 11:39:36 +00:00
|
|
|
#
|
2010-01-26 21:18:36 +00:00
|
|
|
# git-flow -- A collection of Git extensions to provide high-level
|
|
|
|
# repository operations for Vincent Driessen's branching model.
|
2010-01-26 11:39:36 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2010-01-27 23:51:15 +00:00
|
|
|
PREFIX=$(git config --get gitflow.prefix.feature || echo feature/)
|
2010-01-29 11:10:44 +00:00
|
|
|
FLAG_FETCH=0
|
2010-01-27 23:51:15 +00:00
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
usage() {
|
2010-01-28 00:01:53 +00:00
|
|
|
echo "usage: git flow feature [list]"
|
2010-01-27 22:48:39 +00:00
|
|
|
echo " git flow feature start <name> [<base>]"
|
|
|
|
echo " git flow feature finish <name> [<base>]"
|
|
|
|
echo " git flow feature publish <name>"
|
|
|
|
echo " git flow feature track <name>"
|
|
|
|
echo " git flow feature diff <name>"
|
2010-01-26 11:39:36 +00:00
|
|
|
# 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"
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:48:39 +00:00
|
|
|
cmd_default() {
|
2010-01-28 00:01:53 +00:00
|
|
|
cmd_list "$@"
|
2010-01-26 11:39:36 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 00:01:53 +00:00
|
|
|
cmd_list() {
|
2010-01-27 22:48:39 +00:00
|
|
|
FEATURE_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
|
|
|
|
if [ -z "$FEATURE_BRANCHES" ]; then
|
|
|
|
warn "No feature branches exist."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "$FEATURE_BRANCHES" | sed "s?^$PREFIX??g"
|
|
|
|
}
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
cmd_help() {
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
2010-01-28 00:01:53 +00:00
|
|
|
parse_args() {
|
2010-01-29 11:10:44 +00:00
|
|
|
# TODO: When we have a nice structured way of parsing flags with getopt,
|
2010-01-29 11:37:22 +00:00
|
|
|
# implement the following flags:
|
|
|
|
# --fetch, to set FLAG_FETCH=1
|
|
|
|
# --no-fetch, to set FLAG_FETCH=0
|
2010-01-28 00:01:53 +00:00
|
|
|
NAME="$1"
|
|
|
|
BASE="${2:-$DEVELOP_BRANCH}"
|
|
|
|
if [ "$NAME" = "" ]; then
|
|
|
|
echo "Missing argument <name>."
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
BRANCH=$PREFIX$NAME
|
|
|
|
}
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
cmd_start() {
|
|
|
|
parse_args "$@"
|
|
|
|
|
|
|
|
# sanity checks
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-01-26 11:39:36 +00:00
|
|
|
gitflow_require_branch_absent $BRANCH
|
2010-01-29 11:10:44 +00:00
|
|
|
|
|
|
|
# update the local repo with remote changes, if asked
|
|
|
|
if [ $FLAG_FETCH -eq 1 ]; then
|
2010-01-26 13:46:56 +00:00
|
|
|
git fetch -q $ORIGIN $DEVELOP_BRANCH
|
2010-01-26 11:39:36 +00:00
|
|
|
fi
|
|
|
|
|
2010-01-29 11:10:44 +00:00
|
|
|
gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
|
|
|
|
|
2010-01-26 11:39:36 +00:00
|
|
|
# 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
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-01-26 11:39:36 +00:00
|
|
|
gitflow_require_branch $BRANCH
|
2010-01-29 11:10:44 +00:00
|
|
|
|
|
|
|
# update local repo with remote changes first, if asked
|
|
|
|
if [ $FLAG_FETCH -eq 1 ]; then
|
|
|
|
git fetch -q $ORIGIN $BRANCH
|
|
|
|
fi
|
|
|
|
|
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
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-01-26 11:39:36 +00:00
|
|
|
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
|
2010-01-29 09:30:40 +00:00
|
|
|
gitflow_require_clean_working_tree
|
2010-01-26 11:39:36 +00:00
|
|
|
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
|
|
|
|
}
|
2010-01-27 12:57:15 +00:00
|
|
|
|
|
|
|
cmd_diff() {
|
|
|
|
parse_args "$@"
|
|
|
|
# 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?
|
2010-01-28 15:29:34 +00:00
|
|
|
git diff $DEVELOP_BRANCH..$BRANCH
|
2010-01-27 12:57:15 +00:00
|
|
|
}
|