Commit 0161de58 authored by Vincent Driessen's avatar Vincent Driessen

Added implementation of git-flow-init that asks the user interactively what

branches should be used for master and develop and then initializes the Git
repo itself and/or the git-flow branches for him or her.
parent 49094bd9
...@@ -18,57 +18,100 @@ usage() { ...@@ -18,57 +18,100 @@ usage() {
# Default entry when no SUBACTION is given # Default entry when no SUBACTION is given
cmd_default() { cmd_default() {
echo
echo "Summary of actions:"
if ! git rev-parse --git-dir >/dev/null 2>&1; then if ! git rev-parse --git-dir >/dev/null 2>&1; then
git init --quiet git init
echo "- A new git repository at $PWD was created" else
echo "Will try to incorporate git-flow into your current repo."
fi fi
if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then local branch_count
touch "$README"
git add "$README" # add a master branch if no such branch exists yet
git commit --quiet -m "initial commit" local master_branch
if [ "$MASTER_BRANCH" != "master" ]; then if ! git config --get gitflow.branch.master >/dev/null; then
git branch -m master "$MASTER_BRANCH"
fi # first, ask how to create the master branch
echo "- An initial commit was created at branch '$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 fi
echo "Branch name for production releases: [master] \c"
read master_branch
if ! git rev-parse --verify "$MASTER_BRANCH" >/dev/null 2>&1; then master_branch=${master_branch:-master}
die "Cannot find your master branch. Try: git branch -m <mymaster> $MASTER_BRANCH" if [ "$master_branch" != "master" ]; then
git config gitflow.branch.master "$master_branch"
fi
else
master_branch=$(git config --get gitflow.branch.master)
master_branch=${master_branch:-master}
fi fi
gitflow_require_clean_working_tree # add a develop branch if no such branch exists yet
local develop_branch
if ! git config --get gitflow.branch.develop; then
if git remote | grep -q "$ORIGIN"; then # next, ask how to create the develop branch
git fetch -q "$ORIGIN" echo
gitflow_require_branches_equal "$MASTER_BRANCH" "$ORIGIN/$MASTER_BRANCH" 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 fi
echo "Branch name for \"next release\" development: [develop] \c"
read develop_branch
if git rev-parse --verify "$DEVELOP_BRANCH" >/dev/null 2>&1; then develop_branch=${develop_branch:-develop}
gitflow_require_branches_equal "$DEVELOP_BRANCH" "$ORIGIN/$DEVELOP_BRANCH" if [ "$develop_branch" != "develop" ]; then
git config gitflow.branch.develop "$develop_branch"
fi
else else
git checkout -q -b "$DEVELOP_BRANCH" "$MASTER_BRANCH" develop_branch=$(git config --get gitflow.branch.develop)
echo "- A new branch '$DEVELOP_BRANCH' was created" develop_branch=${develop_branch:-develop}
echo "- You are now on branch '$DEVELOP_BRANCH'" fi
# perform an initial commit, if no such commit exists
local initialfile
if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then
echo "A file is required to perform an initial commit."
echo "How would you like to name your initial file? [README] \c"
read initialfile
initialfile=${initialfile:-README}
# point HEAD to the not yet existing master branch
git symbolic-ref HEAD "refs/heads/$master_branch"
touch "$initialfile"
git add "$initialfile"
git commit --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 fi
if ! git remote | grep -q "$ORIGIN"; then if ! gitflow_branch_exists "$develop_branch"; then
if [ "$1" = "" ]; then git branch "$develop_branch" "$master_branch" # base it on the master branch!
echo "- No remote location was added. Try: git remote add $ORIGIN <url>"
else else
git remote add "$ORIGIN" "$1" # TODO: Check: it should be based on the master branch (i.e. master and
echo "- A new remote location '$1' was added" # develop should have a merge base!)
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
fi fi
echo gitflow_require_clean_working_tree
if git remote | grep -q "$ORIGIN"; then # checkout the develop branch to start working
git push "$ORIGIN" "$MASTER_BRANCH" "$DEVELOP_BRANCH" git checkout -q "$develop_branch"
fi
} }
cmd_help() { cmd_help() {
......
...@@ -50,7 +50,6 @@ gitflow_load_settings() { ...@@ -50,7 +50,6 @@ gitflow_load_settings() {
export MASTER_BRANCH=$(git config --get gitflow.branch.master || echo master) export MASTER_BRANCH=$(git config --get gitflow.branch.master || echo master)
export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop || echo develop) export DEVELOP_BRANCH=$(git config --get gitflow.branch.develop || echo develop)
export ORIGIN=$(git config --get gitflow.origin || echo origin) export ORIGIN=$(git config --get gitflow.origin || echo origin)
export README=$(git config --get gitflow.readme || echo README)
} }
# #
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment