Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 1 | # |
| 2 | # git-flow -- A collection of Git extensions to provide high-level |
| 3 | # repository operations for Vincent Driessen's branching model. |
| 4 | # |
| 5 | # Original blog post presenting this model is found at: |
| 6 | # http://nvie.com/archives/323 |
| 7 | # |
| 8 | # Feel free to contribute to this project at: |
| 9 | # http://github.com/nvie/gitflow |
| 10 | # |
| 11 | # Copyright (c) 2010 by Vincent Driessen |
| 12 | # Copyright (c) 2010 by Benedikt Böhm |
| 13 | # |
| 14 | |
| 15 | usage() { |
| 16 | echo "usage: git flow init" |
| 17 | } |
| 18 | |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 19 | # Default entry when no SUBACTION is given |
| 20 | cmd_default() { |
Vincent Driessen | 283b0f7 | 2010-02-15 23:23:14 +0100 | [diff] [blame] | 21 | if ! git rev-parse --git-dir >/dev/null 2>&1; then |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame^] | 22 | git init |
| 23 | else |
| 24 | echo "Will try to incorporate git-flow into your current repo." |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 25 | fi |
| 26 | |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame^] | 27 | local branch_count |
| 28 | |
| 29 | # add a master branch if no such branch exists yet |
| 30 | local master_branch |
| 31 | if ! git config --get gitflow.branch.master >/dev/null; then |
| 32 | |
| 33 | # first, ask how to create the master branch |
| 34 | echo |
| 35 | echo "Which branch should be used for bringing forth production releases?" |
| 36 | branch_count=$(gitflow_all_branches | wc -l) |
| 37 | if [ "$branch_count" -gt 0 ]; then |
| 38 | gitflow_all_branches | sed 's/^.*$/ - &/g' |
| 39 | echo "You may use an existing branch name, or specify a new one." |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 40 | fi |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame^] | 41 | echo "Branch name for production releases: [master] \c" |
| 42 | read master_branch |
| 43 | |
| 44 | master_branch=${master_branch:-master} |
| 45 | if [ "$master_branch" != "master" ]; then |
| 46 | git config gitflow.branch.master "$master_branch" |
| 47 | fi |
| 48 | else |
| 49 | master_branch=$(git config --get gitflow.branch.master) |
| 50 | master_branch=${master_branch:-master} |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 51 | fi |
| 52 | |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame^] | 53 | # add a develop branch if no such branch exists yet |
| 54 | local develop_branch |
| 55 | if ! git config --get gitflow.branch.develop; then |
| 56 | |
| 57 | # next, ask how to create the develop branch |
| 58 | echo |
| 59 | echo "Which branch should be used for developing the \"next release\"?" |
| 60 | branch_count=$(gitflow_all_branches | grep -v "^${master_branch}\$" | wc -l) |
| 61 | if [ "$branch_count" -gt 0 ]; then |
| 62 | gitflow_all_branches | grep -v "^${master_branch}\$" | sed 's/^.*$/ - &/g' |
| 63 | echo "You may use an existing branch name, or specify a new one." |
| 64 | fi |
| 65 | echo "Branch name for \"next release\" development: [develop] \c" |
| 66 | read develop_branch |
| 67 | |
| 68 | develop_branch=${develop_branch:-develop} |
| 69 | if [ "$develop_branch" != "develop" ]; then |
| 70 | git config gitflow.branch.develop "$develop_branch" |
| 71 | fi |
| 72 | else |
| 73 | develop_branch=$(git config --get gitflow.branch.develop) |
| 74 | develop_branch=${develop_branch:-develop} |
| 75 | fi |
| 76 | |
| 77 | # perform an initial commit, if no such commit exists |
| 78 | local initialfile |
| 79 | if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then |
| 80 | echo "A file is required to perform an initial commit." |
| 81 | echo "How would you like to name your initial file? [README] \c" |
| 82 | read initialfile |
| 83 | initialfile=${initialfile:-README} |
| 84 | |
| 85 | # point HEAD to the not yet existing master branch |
| 86 | git symbolic-ref HEAD "refs/heads/$master_branch" |
| 87 | |
| 88 | touch "$initialfile" |
| 89 | git add "$initialfile" |
| 90 | git commit --quiet -m "initial commit" |
| 91 | fi |
| 92 | |
| 93 | # if the selected master branch exists, it's okay, else create it (base on |
| 94 | # the currently checked out branch) |
| 95 | if ! gitflow_branch_exists "$master_branch"; then |
| 96 | git branch "$master_branch" |
| 97 | fi |
| 98 | |
| 99 | if ! gitflow_branch_exists "$develop_branch"; then |
| 100 | git branch "$develop_branch" "$master_branch" # base it on the master branch! |
| 101 | else |
| 102 | # TODO: Check: it should be based on the master branch (i.e. master and |
| 103 | # develop should have a merge base!) |
| 104 | gitflow_test_branches_equal "$develop_branch" "$master_branch" |
| 105 | if [ $? -eq 4 ]; then |
| 106 | warn "fatal: $develop_branch and $master_branch have no common ancestors." |
| 107 | die "fatal: $develop_branch cannot be used for development." |
| 108 | fi |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 109 | fi |
| 110 | |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 111 | gitflow_require_clean_working_tree |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 112 | |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame^] | 113 | # checkout the develop branch to start working |
| 114 | git checkout -q "$develop_branch" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 115 | } |
| 116 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 117 | cmd_help() { |
| 118 | usage |
| 119 | exit 0 |
| 120 | } |