Skip to content
Newer
Older
100644 178 lines (154 sloc) 4.25 KB
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
1 #
6c2d30b @nvie Structurally replace gitflow by git-flow, as a true git extension.
authored Jan 26, 2010
2 # git-flow -- A collection of Git extensions to provide high-level
3 # repository operations for Vincent Driessen's branching model.
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
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
ab3dc49 @nvie Fix: respect the VERSION_PREFIX in hotfix releases, too.
authored Jan 29, 2010
15 VERSION_PREFIX=$(git config --get gitflow.prefix.versiontag)
49dd62b @hollow refactor git config calls to global variables
hollow authored Jan 28, 2010
16 PREFIX=$(git config --get gitflow.prefix.hotfix || echo hotfix/)
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored Jan 29, 2010
17 FLAG_FETCH=1
49dd62b @hollow refactor git config calls to global variables
hollow authored Jan 27, 2010
18
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
19 usage() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
20 echo "usage: git flow hotfix [list] [-v]"
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored Jan 27, 2010
21 echo " git flow hotfix start <version> [<base>]"
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
22 echo " git flow hotfix finish <version>"
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
23 }
24
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored Jan 27, 2010
25 cmd_default() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
26 cmd_list "$@"
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
27 }
28
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
29 cmd_list() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
30 DEFINE_boolean verbose false 'verbose (more) output' v
31 parse_args "$@"
32
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored Jan 27, 2010
33 HOTFIX_BRANCHES="$(echo "$LOCAL_BRANCHES" | grep "^$PREFIX")"
34 if [ -z "$HOTFIX_BRANCHES" ]; then
35 warn "No hotfix branches exist."
36 exit 0
37 fi
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
38
39 CURRENT_BRANCH=$(git branch | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g')
40 SHORT_NAMES=$(echo "$HOTFIX_BRANCHES" | sed "s?^$PREFIX??g")
41 # determine column width first
42 width=0
43 for branch in $SHORT_NAMES; do
44 len=$(($(echo "$branch" | wc -c) - 1))
45 width=$(max $width $len)
46 done
47 width=$(($width + 3))
48
49 for branch in $SHORT_NAMES; do
50 fullname="$PREFIX$branch"
51 base=$(git merge-base "$fullname" "$MASTER_BRANCH")
52 master_sha=$(git rev-parse "$MASTER_BRANCH")
53 branch_sha=$(git rev-parse "$fullname")
54 if [ "$fullname" = "$CURRENT_BRANCH" ]; then
55 printf "* "
56 else
57 printf " "
58 fi
59 if flag verbose; then
60 printf "%-${width}s" "$branch"
61 if [ "$branch_sha" = "$master_sha" ]; then
62 printf "(no commits yet)"
63 else
64 tagname=$(git name-rev --tags --no-undefined --name-only $base)
65 if [ "$tagname" != "" ]; then
66 nicename="$tagname"
67 else
68 nicename="$(git rev-parse --short $base)"
69 fi
70 printf "(based on $nicename)"
71 fi
72 else
73 printf "%s" "$branch"
74 fi
75 echo
76 done
186d2b5 @nvie Refactored the subcommand invocation logic to form a more hierarchica…
authored Jan 27, 2010
77 }
78
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
79 cmd_help() {
80 usage
81 exit 0
82 }
83
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
84 parse_args() {
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
85 # parse options
86 FLAGS "$@" || exit $?
87 eval set -- "${FLAGS_ARGV}"
88
89 # read arguments into global variables
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
90 VERSION="$1"
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
91 BRANCH=$PREFIX$VERSION
92 }
93
94 require_version_arg() {
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
95 if [ "$VERSION" = "" ]; then
3c337fb @nvie Added -v (--verbose) flags to list subaction of all subcommands.
authored Feb 4, 2010
96 warn "Missing argument <version>"
b866b01 @nvie Give all subcommands an optional setup() function that will be called…
authored Jan 28, 2010
97 usage
98 exit 1
99 fi
100 }
101
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
102 require_base_is_on_master() {
103 if ! git branch --contains "$BASE" 2>/dev/null \
104 | sed 's/[* ] //g' \
105 | grep -q "^$MASTER_BRANCH\$"; then
106 die "fatal: Given base '$BASE' is not a valid commit on '$MASTER_BRANCH'."
107 fi
108 }
109
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
110 cmd_start() {
111 parse_args "$@"
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
112 BASE="${2:-$MASTER_BRANCH}"
113 require_version_arg
114 require_base_is_on_master
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
115
116 # sanity checks
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
authored Jan 29, 2010
117 gitflow_require_clean_working_tree
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored Jan 29, 2010
118 if [ $FLAG_FETCH -eq 1 ]; then
119 git fetch -q $ORIGIN $MASTER_BRANCH
120 fi
350e715 @hollow make origin configurable
hollow authored Jan 26, 2010
121 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
122 gitflow_require_branch_absent $BRANCH
123
124 # create branch
125 git checkout -b $BRANCH $BASE
126
127 echo
128 echo "Summary of actions:"
129 echo "- A new branch '$BRANCH' was created, based on '$BASE'"
130 echo "- You are now on branch '$BRANCH'"
131 echo
132 echo "Follow-up actions:"
133 echo "- Bump the version number now!"
134 echo "- Start committing your hot fixes"
135 echo "- When done, run:"
136 echo
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
137 echo " git flow hotfix finish '$VERSION'"
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
138 echo
139 }
140
141 cmd_finish() {
142 parse_args "$@"
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
143 require_version_arg
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
144
145 # sanity checks
4838644 @nvie Replace gitflow_check_ prefixes by gitflow_require_ prefixes, for con…
authored Jan 29, 2010
146 gitflow_require_clean_working_tree
2acfffd @nvie Make the 'to fetch or not to fetch' flag explicit in the other comman…
authored Jan 29, 2010
147 if [ $FLAG_FETCH -eq 1 ]; then
148 git fetch -q $ORIGIN $MASTER_BRANCH
149 git fetch -q $ORIGIN $DEVELOP_BRANCH
150 fi
350e715 @hollow make origin configurable
hollow authored Jan 26, 2010
151 gitflow_require_branches_equal $MASTER_BRANCH $ORIGIN/$MASTER_BRANCH
152 gitflow_require_branches_equal $DEVELOP_BRANCH $ORIGIN/$DEVELOP_BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
153
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
154 # merge into master
155 git checkout $MASTER_BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
156 git merge --no-ff $BRANCH
ab3dc49 @nvie Fix: respect the VERSION_PREFIX in hotfix releases, too.
authored Jan 29, 2010
157 git tag $VERSION_PREFIX$VERSION
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
158
159 # merge into develop if we fixed a master issue
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
160 git checkout $DEVELOP_BRANCH
161 git merge --no-ff $BRANCH
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
162
163 # delete branch
164 git branch -d $BRANCH
165
166 # TODO: Implement an optional push to master
167 # git push origin develop; git push origin master; git push --tags origin
168
169 echo
170 echo "Summary of actions:"
350e715 @hollow make origin configurable
hollow authored Jan 26, 2010
171 echo "- Latest objects have been fetched from '$ORIGIN'"
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
172 echo "- Hotfix branch has been merged into '$MASTER_BRANCH'"
ab3dc49 @nvie Fix: respect the VERSION_PREFIX in hotfix releases, too.
authored Jan 29, 2010
173 echo "- The hotfix was tagged '$VERSION_PREFIX$VERSION'"
010252a @nvie Added an optional <base> argument to all start subactions.
authored Feb 4, 2010
174 echo "- Hotfix branch has been back-merged into '$DEVELOP_BRANCH'"
00ccea6 @hollow refactor the whole thing
hollow authored Jan 26, 2010
175 echo "- Hotfix branch '$BRANCH' has been deleted"
176 echo
177 }
Something went wrong with that request. Please try again.