2010-01-27 22:48:39 +00:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
2010-04-04 14:10:17 +00:00
|
|
|
# Copyright 2010 Vincent Driessen. All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions and the following disclaimer.
|
|
|
|
#
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY VINCENT DRIESSEN ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
|
|
|
# EVENT SHALL VINCENT DRIESSEN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
|
|
|
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
|
|
|
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
#
|
|
|
|
# The views and conclusions contained in the software and documentation are
|
|
|
|
# those of the authors and should not be interpreted as representing official
|
|
|
|
# policies, either expressed or implied, of Vincent Driessen.
|
2010-01-27 22:48:39 +00:00
|
|
|
#
|
|
|
|
|
|
|
|
usage() {
|
2010-02-24 00:37:07 +00:00
|
|
|
echo "usage: git flow init [-f]"
|
2010-01-27 22:48:39 +00:00
|
|
|
}
|
|
|
|
|
2010-02-20 13:30:16 +00:00
|
|
|
parse_args() {
|
|
|
|
# parse options
|
|
|
|
FLAGS "$@" || exit $?
|
|
|
|
eval set -- "${FLAGS_ARGV}"
|
|
|
|
}
|
|
|
|
|
2010-01-27 22:48:39 +00:00
|
|
|
# Default entry when no SUBACTION is given
|
|
|
|
cmd_default() {
|
2010-02-20 13:30:16 +00:00
|
|
|
DEFINE_boolean force false 'force setting of gitflow branches, even if already configured' f
|
|
|
|
parse_args "$@"
|
|
|
|
|
2010-02-15 22:23:14 +00:00
|
|
|
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
2010-02-18 11:07:34 +00:00
|
|
|
git init
|
|
|
|
else
|
2010-02-20 13:30:16 +00:00
|
|
|
# assure that we are not working in a repo with local changes
|
2010-02-21 20:31:03 +00:00
|
|
|
git_repo_is_headless || require_clean_working_tree
|
2010-02-20 13:30:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# running git flow init on an already initialized repo is fine
|
|
|
|
if gitflow_is_initialized && ! flag force; then
|
|
|
|
warn "Already initialized for gitflow."
|
|
|
|
warn "To force reinitialization, use: git flow init -f"
|
|
|
|
exit 0
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-18 11:07:34 +00:00
|
|
|
local branch_count
|
2010-02-20 15:23:47 +00:00
|
|
|
local answer
|
2010-02-18 11:07:34 +00:00
|
|
|
|
|
|
|
# add a master branch if no such branch exists yet
|
|
|
|
local master_branch
|
2010-02-20 13:30:16 +00:00
|
|
|
if gitflow_has_master_configured && ! flag force; then
|
|
|
|
master_branch=$(git config --get gitflow.branch.master)
|
|
|
|
else
|
|
|
|
# Two cases are distinguished:
|
|
|
|
# 1. A fresh git repo (without any branches)
|
|
|
|
# We will create a new master/develop branch for the user
|
|
|
|
# 2. Some branches do already exist
|
|
|
|
# We will disallow creation of new master/develop branches and
|
|
|
|
# rather allow to use existing branches for git-flow.
|
|
|
|
local default_suggestion
|
|
|
|
local should_check_existence
|
2010-02-21 20:31:03 +00:00
|
|
|
branch_count=$(git_local_branches | wc -l)
|
2010-02-20 13:30:16 +00:00
|
|
|
if [ "$branch_count" -eq 0 ]; then
|
|
|
|
echo "No branches exist yet. Base branches must be created now."
|
|
|
|
should_check_existence=NO
|
2010-03-23 20:10:13 +00:00
|
|
|
default_suggestion=$(git config --get gitflow.branch.master || echo master)
|
2010-02-20 13:30:16 +00:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "Which branch should be used for bringing forth production releases?"
|
2010-02-21 20:31:03 +00:00
|
|
|
git_local_branches | sed 's/^.*$/ - &/g'
|
2010-02-20 13:30:16 +00:00
|
|
|
|
|
|
|
should_check_existence=YES
|
|
|
|
default_suggestion=
|
2010-03-23 20:10:13 +00:00
|
|
|
for guess in $(git config --get gitflow.branch.master) \
|
|
|
|
'production' 'main' 'master'; do
|
2010-02-21 20:31:03 +00:00
|
|
|
if git_local_branch_exists "$guess"; then
|
2010-02-20 13:30:16 +00:00
|
|
|
default_suggestion="$guess"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Branch name for production releases: [$default_suggestion] "
|
2010-02-20 13:30:16 +00:00
|
|
|
read answer
|
|
|
|
master_branch=${answer:-$default_suggestion}
|
|
|
|
|
|
|
|
# check existence in case of an already existing repo
|
|
|
|
if [ "$should_check_existence" = "YES" ]; then
|
2010-02-21 20:31:03 +00:00
|
|
|
git_local_branch_exists "$master_branch" || \
|
2010-02-20 13:30:16 +00:00
|
|
|
die "Local branch '$master_branch' does not exist."
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
2010-02-18 11:32:20 +00:00
|
|
|
|
|
|
|
# store the name of the master branch
|
|
|
|
git config gitflow.branch.master "$master_branch"
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-18 11:07:34 +00:00
|
|
|
# add a develop branch if no such branch exists yet
|
|
|
|
local develop_branch
|
2010-02-20 13:30:16 +00:00
|
|
|
if gitflow_has_develop_configured && ! flag force; then
|
|
|
|
develop_branch=$(git config --get gitflow.branch.develop)
|
|
|
|
else
|
|
|
|
# Again, the same two cases as with the master selection are
|
|
|
|
# considered (fresh repo or repo that contains branches)
|
|
|
|
local default_suggestion
|
|
|
|
local should_check_existence
|
2010-02-21 20:31:03 +00:00
|
|
|
branch_count=$(git_local_branches | grep -v "^${master_branch}\$" | wc -l)
|
2010-02-20 13:30:16 +00:00
|
|
|
if [ "$branch_count" -eq 0 ]; then
|
|
|
|
should_check_existence=NO
|
2010-03-23 20:10:13 +00:00
|
|
|
default_suggestion=$(git config --get gitflow.branch.develop || echo develop)
|
2010-02-20 13:30:16 +00:00
|
|
|
else
|
|
|
|
echo
|
|
|
|
echo "Which branch should be used for integration of the \"next release\"?"
|
2010-02-21 20:31:03 +00:00
|
|
|
git_local_branches | grep -v "^${master_branch}\$" | sed 's/^.*$/ - &/g'
|
2010-02-20 13:30:16 +00:00
|
|
|
|
|
|
|
should_check_existence=YES
|
|
|
|
default_suggestion=
|
2010-03-23 20:10:13 +00:00
|
|
|
for guess in $(git config --get gitflow.branch.develop) \
|
|
|
|
'develop' 'int' 'integration' 'master'; do
|
2010-02-21 20:31:03 +00:00
|
|
|
if git_local_branch_exists "$guess"; then
|
2010-02-20 13:30:16 +00:00
|
|
|
default_suggestion="$guess"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Branch name for \"next release\" development: [$default_suggestion] "
|
2010-02-20 13:30:16 +00:00
|
|
|
read answer
|
|
|
|
develop_branch=${answer:-$default_suggestion}
|
|
|
|
|
|
|
|
if [ "$master_branch" = "$develop_branch" ]; then
|
|
|
|
die "Production and integration branches should differ."
|
|
|
|
fi
|
|
|
|
|
|
|
|
# check existence in case of an already existing repo
|
|
|
|
if [ "$should_check_existence" = "YES" ]; then
|
2010-02-21 20:31:03 +00:00
|
|
|
git_local_branch_exists "$develop_branch" || \
|
2010-02-20 13:30:16 +00:00
|
|
|
die "Local branch '$develop_branch' does not exist."
|
2010-02-18 11:07:34 +00:00
|
|
|
fi
|
2010-02-18 11:32:20 +00:00
|
|
|
|
|
|
|
# store the name of the develop branch
|
|
|
|
git config gitflow.branch.develop "$develop_branch"
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-20 13:30:16 +00:00
|
|
|
# Creation of HEAD
|
|
|
|
# ----------------
|
|
|
|
# We create a HEAD now, if it does not exist yet (in a fresh repo). We need
|
|
|
|
# it to be able to create new branches.
|
2010-02-20 15:13:23 +00:00
|
|
|
local created_gitflow_branch=0
|
2010-02-18 11:07:34 +00:00
|
|
|
if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then
|
|
|
|
git symbolic-ref HEAD "refs/heads/$master_branch"
|
2010-02-18 11:32:20 +00:00
|
|
|
git commit --allow-empty --quiet -m "Initial commit"
|
2010-02-20 15:13:23 +00:00
|
|
|
created_gitflow_branch=1
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-20 13:30:16 +00:00
|
|
|
# Creation of master
|
|
|
|
# ------------------
|
|
|
|
# At this point, there always is a master branch: either it existed already
|
|
|
|
# (and was picked interactively as the production branch) or it has just
|
|
|
|
# been created in a fresh repo
|
2010-01-27 22:48:39 +00:00
|
|
|
|
2010-02-20 13:30:16 +00:00
|
|
|
# Creation of develop
|
|
|
|
# -------------------
|
|
|
|
# The develop branch possibly does not exist yet. This is the case when,
|
|
|
|
# in a git init'ed repo with one or more commits, master was picked as the
|
|
|
|
# default production branch and develop was "created". We should create
|
|
|
|
# the develop branch now in that case (we base it on master, of course)
|
2010-02-21 20:31:03 +00:00
|
|
|
if ! git_local_branch_exists "$develop_branch"; then
|
2010-03-25 14:30:58 +00:00
|
|
|
git branch --no-track "$develop_branch" "$master_branch"
|
2010-02-20 15:13:23 +00:00
|
|
|
created_gitflow_branch=1
|
2010-01-27 22:48:39 +00:00
|
|
|
fi
|
|
|
|
|
2010-02-20 13:30:16 +00:00
|
|
|
# assert the gitflow repo has been correctly initialized
|
|
|
|
gitflow_is_initialized
|
2010-01-27 22:48:39 +00:00
|
|
|
|
2010-02-20 15:13:23 +00:00
|
|
|
# switch to develop branch if its newly created
|
|
|
|
if [ $created_gitflow_branch -eq 1 ]; then
|
|
|
|
git checkout -q "$develop_branch"
|
|
|
|
fi
|
2010-02-18 11:32:20 +00:00
|
|
|
|
2010-02-20 15:23:47 +00:00
|
|
|
# finally, ask the user for naming conventions (branch and tag prefixes)
|
2010-03-23 20:10:13 +00:00
|
|
|
if flag force || \
|
|
|
|
! git config --get gitflow.prefix.feature >/dev/null 2>&1 ||
|
|
|
|
! git config --get gitflow.prefix.release >/dev/null 2>&1 ||
|
|
|
|
! git config --get gitflow.prefix.hotfix >/dev/null 2>&1 ||
|
|
|
|
! git config --get gitflow.prefix.support >/dev/null 2>&1 ||
|
|
|
|
! git config --get gitflow.prefix.versiontag >/dev/null 2>&1; then
|
|
|
|
echo
|
|
|
|
echo "How to name your supporting branch prefixes?"
|
|
|
|
fi
|
2010-02-20 15:23:47 +00:00
|
|
|
|
|
|
|
local prefix
|
|
|
|
|
|
|
|
# Feature branches
|
2010-02-20 15:46:38 +00:00
|
|
|
if ! git config --get gitflow.prefix.feature >/dev/null 2>&1 || flag force; then
|
|
|
|
default_suggestion=$(git config --get gitflow.prefix.feature || echo feature/)
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Feature branches? [$default_suggestion] "
|
2010-02-20 15:46:38 +00:00
|
|
|
read answer
|
|
|
|
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
|
|
|
|
git config gitflow.prefix.feature "$prefix"
|
|
|
|
fi
|
2010-02-20 15:23:47 +00:00
|
|
|
|
|
|
|
# Release branches
|
2010-02-20 15:46:38 +00:00
|
|
|
if ! git config --get gitflow.prefix.release >/dev/null 2>&1 || flag force; then
|
|
|
|
default_suggestion=$(git config --get gitflow.prefix.release || echo release/)
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Release branches? [$default_suggestion] "
|
2010-02-20 15:46:38 +00:00
|
|
|
read answer
|
|
|
|
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
|
|
|
|
git config gitflow.prefix.release "$prefix"
|
|
|
|
fi
|
|
|
|
|
2010-02-20 15:23:47 +00:00
|
|
|
|
|
|
|
# Hotfix branches
|
2010-02-20 15:46:38 +00:00
|
|
|
if ! git config --get gitflow.prefix.hotfix >/dev/null 2>&1 || flag force; then
|
|
|
|
default_suggestion=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Hotfix branches? [$default_suggestion] "
|
2010-02-20 15:46:38 +00:00
|
|
|
read answer
|
|
|
|
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
|
|
|
|
git config gitflow.prefix.hotfix "$prefix"
|
|
|
|
fi
|
|
|
|
|
2010-02-20 15:23:47 +00:00
|
|
|
|
|
|
|
# Support branches
|
2010-02-20 15:46:38 +00:00
|
|
|
if ! git config --get gitflow.prefix.support >/dev/null 2>&1 || flag force; then
|
|
|
|
default_suggestion=$(git config --get gitflow.prefix.support || echo support/)
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Support branches? [$default_suggestion] "
|
2010-02-20 15:46:38 +00:00
|
|
|
read answer
|
|
|
|
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
|
|
|
|
git config gitflow.prefix.support "$prefix"
|
|
|
|
fi
|
|
|
|
|
2010-02-20 15:23:47 +00:00
|
|
|
|
|
|
|
# Version tag prefix
|
2010-02-20 15:46:38 +00:00
|
|
|
if ! git config --get gitflow.prefix.versiontag >/dev/null 2>&1 || flag force; then
|
|
|
|
default_suggestion=$(git config --get gitflow.prefix.versiontag || echo "")
|
2010-03-23 20:19:54 +00:00
|
|
|
printf "Version tag prefix? [$default_suggestion] "
|
2010-02-20 15:46:38 +00:00
|
|
|
read answer
|
|
|
|
[ "$answer" = "-" ] && prefix= || prefix=${answer:-$default_suggestion}
|
|
|
|
git config gitflow.prefix.versiontag "$prefix"
|
|
|
|
fi
|
|
|
|
|
2010-02-18 11:32:20 +00:00
|
|
|
|
|
|
|
# TODO: what to do with origin?
|
2010-01-27 22:48:39 +00:00
|
|
|
}
|
|
|
|
|
2010-01-28 00:01:53 +00:00
|
|
|
cmd_help() {
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
}
|