| # |
| # 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 |
| local master_branch |
| if ! git config --get gitflow.branch.master >/dev/null; 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} |
| 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 |
| |
| # add a develop branch if no such branch exists yet |
| local develop_branch |
| if ! git config --get gitflow.branch.develop; 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} |
| if [ "$develop_branch" != "develop" ]; then |
| git config gitflow.branch.develop "$develop_branch" |
| fi |
| else |
| develop_branch=$(git config --get gitflow.branch.develop) |
| develop_branch=${develop_branch:-develop} |
| 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 |
| |
| if ! gitflow_branch_exists "$develop_branch"; then |
| git branch "$develop_branch" "$master_branch" # base it on the master branch! |
| else |
| # TODO: Check: it should be based on the master branch (i.e. master and |
| # 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 |
| |
| gitflow_require_clean_working_tree |
| |
| # checkout the develop branch to start working |
| git checkout -q "$develop_branch" |
| } |
| |
| cmd_help() { |
| usage |
| exit 0 |
| } |