blob: c38dab65a1844af9e7d9c2b82becff0b16948067 [file] [log] [blame]
Vincent Driessen186d2b52010-01-27 23:48:39 +01001#
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
15usage() {
16 echo "usage: git flow init"
17}
18
Vincent Driessen186d2b52010-01-27 23:48:39 +010019# Default entry when no SUBACTION is given
20cmd_default() {
Vincent Driessen283b0f72010-02-15 23:23:14 +010021 if ! git rev-parse --git-dir >/dev/null 2>&1; then
Vincent Driessen0161de52010-02-18 12:07:34 +010022 git init
23 else
24 echo "Will try to incorporate git-flow into your current repo."
Vincent Driessen186d2b52010-01-27 23:48:39 +010025 fi
26
Vincent Driessen0161de52010-02-18 12:07:34 +010027 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 Driessen186d2b52010-01-27 23:48:39 +010040 fi
Vincent Driessen0161de52010-02-18 12:07:34 +010041 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 Driessen186d2b52010-01-27 23:48:39 +010051 fi
52
Vincent Driessen0161de52010-02-18 12:07:34 +010053 # 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 Driessen186d2b52010-01-27 23:48:39 +0100109 fi
110
Vincent Driessen48386442010-01-29 10:30:40 +0100111 gitflow_require_clean_working_tree
Vincent Driessen186d2b52010-01-27 23:48:39 +0100112
Vincent Driessen0161de52010-02-18 12:07:34 +0100113 # checkout the develop branch to start working
114 git checkout -q "$develop_branch"
Vincent Driessen186d2b52010-01-27 23:48:39 +0100115}
116
Vincent Driessenb866b012010-01-28 01:01:53 +0100117cmd_help() {
118 usage
119 exit 0
120}