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 |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 30 | # TODO: Distinguish two cases: |
| 31 | # 1. NO BRANCHES EXIST AT ALL! (fresh repo): |
| 32 | # allow a name for the branch-to-be-created |
| 33 | # 2. THERE EXIST SOME BRANCHES |
| 34 | # master must be based on (or *be*) one of those! |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 35 | local master_branch |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 36 | master_branch=$(git config --get gitflow.branch.master) |
| 37 | if [ "$master_branch" = "" ]; then |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 38 | # first, ask how to create the master branch |
| 39 | echo |
| 40 | echo "Which branch should be used for bringing forth production releases?" |
| 41 | branch_count=$(gitflow_all_branches | wc -l) |
| 42 | if [ "$branch_count" -gt 0 ]; then |
| 43 | gitflow_all_branches | sed 's/^.*$/ - &/g' |
| 44 | 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] | 45 | fi |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 46 | echo "Branch name for production releases: [master] \c" |
| 47 | read master_branch |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 48 | master_branch=${master_branch:-master} |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 49 | |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 50 | # store the name of the master branch |
| 51 | git config gitflow.branch.master "$master_branch" |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 52 | fi |
| 53 | |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 54 | # add a develop branch if no such branch exists yet |
| 55 | local develop_branch |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 56 | develop_branch=$(git config --get gitflow.branch.develop) |
| 57 | if [ "$develop_branch" = "" ]; then |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 58 | # next, ask how to create the develop branch |
| 59 | echo |
| 60 | echo "Which branch should be used for developing the \"next release\"?" |
| 61 | branch_count=$(gitflow_all_branches | grep -v "^${master_branch}\$" | wc -l) |
| 62 | if [ "$branch_count" -gt 0 ]; then |
| 63 | gitflow_all_branches | grep -v "^${master_branch}\$" | sed 's/^.*$/ - &/g' |
| 64 | echo "You may use an existing branch name, or specify a new one." |
| 65 | fi |
| 66 | echo "Branch name for \"next release\" development: [develop] \c" |
| 67 | read develop_branch |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 68 | develop_branch=${develop_branch:-develop} |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 69 | |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 70 | # store the name of the develop branch |
| 71 | git config gitflow.branch.develop "$develop_branch" |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 72 | fi |
| 73 | |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 74 | # create a HEAD now, if it does not exist yet (in a just init'ed repo) |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 75 | if ! git rev-parse --quiet --verify HEAD >/dev/null 2>&1; then |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 76 | git symbolic-ref HEAD "refs/heads/$master_branch" |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 77 | git commit --allow-empty --quiet -m "Initial commit" |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 78 | fi |
| 79 | |
| 80 | # if the selected master branch exists, it's okay, else create it (base on |
| 81 | # the currently checked out branch) |
| 82 | if ! gitflow_branch_exists "$master_branch"; then |
| 83 | git branch "$master_branch" |
| 84 | fi |
| 85 | |
| 86 | if ! gitflow_branch_exists "$develop_branch"; then |
| 87 | git branch "$develop_branch" "$master_branch" # base it on the master branch! |
| 88 | else |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 89 | # TODO: this test should be moved up, in the selection of the develop |
| 90 | # branch! Branches that do not have a merge base with master shouldn't |
| 91 | # be allowed to pick in the first place! |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 92 | gitflow_test_branches_equal "$develop_branch" "$master_branch" |
| 93 | if [ $? -eq 4 ]; then |
| 94 | warn "fatal: $develop_branch and $master_branch have no common ancestors." |
| 95 | die "fatal: $develop_branch cannot be used for development." |
| 96 | fi |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 97 | fi |
| 98 | |
Vincent Driessen | 4838644 | 2010-01-29 10:30:40 +0100 | [diff] [blame] | 99 | gitflow_require_clean_working_tree |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 100 | |
Vincent Driessen | 0161de5 | 2010-02-18 12:07:34 +0100 | [diff] [blame] | 101 | # checkout the develop branch to start working |
| 102 | git checkout -q "$develop_branch" |
Vincent Driessen | 6188206 | 2010-02-18 12:32:20 +0100 | [diff] [blame^] | 103 | |
| 104 | # TODO: finally, ask the user for naming convention preferences |
| 105 | # i.e. tag prefixes, prefixes for supporting branches, etc. |
| 106 | |
| 107 | # TODO: what to do with origin? |
Vincent Driessen | 186d2b5 | 2010-01-27 23:48:39 +0100 | [diff] [blame] | 108 | } |
| 109 | |
Vincent Driessen | b866b01 | 2010-01-28 01:01:53 +0100 | [diff] [blame] | 110 | cmd_help() { |
| 111 | usage |
| 112 | exit 0 |
| 113 | } |