61882067af
They are required. Their existence tells us that this repository is gitflow-enabled. Added some TODO notes to implement.
113 lines
3.7 KiB
Text
113 lines
3.7 KiB
Text
#
|
|
# 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 init"
|
|
}
|
|
|
|
# Default entry when no SUBACTION is given
|
|
cmd_default() {
|
|
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
|
git init
|
|
else
|
|
echo "Will try to incorporate git-flow into your current repo."
|
|
fi
|
|
|
|
local branch_count
|
|
|
|
# add a master branch if no such branch exists yet
|
|
# TODO: Distinguish two cases:
|
|
# 1. NO BRANCHES EXIST AT ALL! (fresh repo):
|
|
# allow a name for the branch-to-be-created
|
|
# 2. THERE EXIST SOME BRANCHES
|
|
# master must be based on (or *be*) one of those!
|
|
local master_branch
|
|
master_branch=$(git config --get gitflow.branch.master)
|
|
if [ "$master_branch" = "" ]; then
|
|
# first, ask how to create the master branch
|
|
echo
|
|
echo "Which branch should be used for bringing forth production releases?"
|
|
branch_count=$(gitflow_all_branches | wc -l)
|
|
if [ "$branch_count" -gt 0 ]; then
|
|
gitflow_all_branches | sed 's/^.*$/ - &/g'
|
|
echo "You may use an existing branch name, or specify a new one."
|
|
fi
|
|
echo "Branch name for production releases: [master] \c"
|
|
read master_branch
|
|
master_branch=${master_branch:-master}
|
|
|
|
# store the name of the master branch
|
|
git config gitflow.branch.master "$master_branch"
|
|
fi
|
|
|
|
# add a develop branch if no such branch exists yet
|
|
local develop_branch
|
|
develop_branch=$(git config --get gitflow.branch.develop)
|
|
if [ "$develop_branch" = "" ]; then
|
|
# next, ask how to create the develop branch
|
|
echo
|
|
echo "Which branch should be used for developing the \"next release\"?"
|
|
branch_count=$(gitflow_all_branches | grep -v "^${master_branch}\$" | wc -l)
|
|
if [ "$branch_count" -gt 0 ]; then
|
|
gitflow_all_branches | grep -v "^${master_branch}\$" | sed 's/^.*$/ - &/g'
|
|
echo "You may use an existing branch name, or specify a new one."
|
|
fi
|
|
echo "Branch name for \"next release\" development: [develop] \c"
|
|
read develop_branch
|
|
develop_branch=${develop_branch:-develop}
|
|
|
|
# store the name of the develop branch
|
|
git config gitflow.branch.develop "$develop_branch"
|
|
fi
|
|
|
|
# create a HEAD now, if it does not exist yet (in a just init'ed repo)
|
|
if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then
|
|
git symbolic-ref HEAD "refs/heads/$master_branch"
|
|
git commit --allow-empty --quiet -m "Initial commit"
|
|
fi
|
|
|
|
# if the selected master branch exists, it's okay, else create it (base on
|
|
# the currently checked out branch)
|
|
if ! gitflow_branch_exists "$master_branch"; then
|
|
git branch "$master_branch"
|
|
fi
|
|
|
|
if ! gitflow_branch_exists "$develop_branch"; then
|
|
git branch "$develop_branch" "$master_branch" # base it on the master branch!
|
|
else
|
|
# TODO: this test should be moved up, in the selection of the develop
|
|
# branch! Branches that do not have a merge base with master shouldn't
|
|
# be allowed to pick in the first place!
|
|
gitflow_test_branches_equal "$develop_branch" "$master_branch"
|
|
if [ $? -eq 4 ]; then
|
|
warn "fatal: $develop_branch and $master_branch have no common ancestors."
|
|
die "fatal: $develop_branch cannot be used for development."
|
|
fi
|
|
fi
|
|
|
|
gitflow_require_clean_working_tree
|
|
|
|
# checkout the develop branch to start working
|
|
git checkout -q "$develop_branch"
|
|
|
|
# TODO: finally, ask the user for naming convention preferences
|
|
# i.e. tag prefixes, prefixes for supporting branches, etc.
|
|
|
|
# TODO: what to do with origin?
|
|
}
|
|
|
|
cmd_help() {
|
|
usage
|
|
exit 0
|
|
}
|