| # |
| # git-flow -- A collection of Git extensions 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 hotfix" |
| echo " git flow hotfix start <version> [<base>]" |
| echo " git flow hotfix finish <version> [<base>]" |
| # 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" |
| } |
| |
| parse_args() { |
| VERSION="$1" |
| BASE="${2:-$MASTER_BRANCH}" |
| if [ "$VERSION" = "" ]; then |
| echo "Missing argument <version>." |
| usage |
| exit 1 |
| fi |
| PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/) |
| BRANCH=$PREFIX$VERSION |
| } |
| |
| cmd_default() { |
| # TODO: Refactor getting this prefix into a general function |
| PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/) |
| HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")" |
| if [ -z "$HOTFIX_BRANCHES" ]; then |
| warn "No hotfix branches exist." |
| exit 0 |
| fi |
| echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g" |
| } |
| |
| cmd_help() { |
| usage |
| exit 0 |
| } |
| |
| cmd_start() { |
| parse_args "$@" |
| |
| # sanity checks |
| gitflow_check_clean_working_tree |
| git fetch -q $ORIGIN |
| gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH |
| gitflow_require_branch_absent $BRANCH |
| |
| # 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 "Follow-up actions:" |
| echo "- Bump the version number now!" |
| echo "- Start committing your hot fixes" |
| echo "- When done, run:" |
| echo |
| echo " git flow finish hotfix '$HOTFIX_BRANCH'" |
| echo |
| } |
| |
| cmd_finish() { |
| parse_args "$@" |
| |
| # sanity checks |
| gitflow_check_clean_working_tree |
| git fetch -q $ORIGIN $MASTER_BRANCH |
| git fetch -q $ORIGIN $DEVELOP_BRANCH |
| gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH |
| gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH |
| |
| # merge into BASE |
| git checkout $BASE |
| git merge --no-ff $BRANCH |
| git tag v$VERSION |
| |
| # merge into develop if we fixed a master issue |
| # TODO: merge into support branch |
| if [ "$BASE" = "$MASTER_BRANCH" ]; then |
| git checkout $DEVELOP_BRANCH |
| git merge --no-ff $BRANCH |
| fi |
| |
| # delete branch |
| git branch -d $BRANCH |
| |
| # TODO: Implement an optional push to master |
| # git push origin develop; git push origin master; git push --tags origin |
| |
| echo |
| echo "Summary of actions:" |
| echo "- Latest objects have been fetched from '$ORIGIN'" |
| echo "- Hotfix branch has been merged into '$BASE'" |
| echo "- The hotfix was tagged 'v$VERSION'" |
| if [ "$BASE" = "$MASTER_BRANCH" ]; then |
| echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'" |
| fi |
| echo "- Hotfix branch '$BRANCH' has been deleted" |
| echo |
| } |