@@ -18,21 +18,13 @@ if [ "$DEBUG" = "yes" ]; then
18
18
set -x
19
19
fi
20
20
21
- export GIT_DIR=$( git rev-parse --git-dir)
22
21
export GITFLOW_DIR=$( dirname " $0 " )
22
+ export GIT_DIR=$( git rev-parse --git-dir)
23
23
export MASTER_BRANCH=$( git config --get gitflow.branch.master || echo master)
24
24
export DEVELOP_BRANCH=$( git config --get gitflow.branch.develop || echo develop)
25
25
export ORIGIN=$( git config --get gitflow.origin || echo origin)
26
26
export README=$( git config --get gitflow.readme || echo README)
27
27
28
- warn () { echo " $@ " >&2 ; }
29
- die () { warn " $@ " ; exit 1; }
30
-
31
- has () {
32
- local item=$1 ; shift
33
- echo " $@ " | grep -q " $item "
34
- }
35
-
36
28
usage () {
37
29
echo " usage: git flow <subcommand>"
38
30
echo
@@ -53,11 +45,12 @@ main() {
53
45
exit 1
54
46
fi
55
47
48
+ # load common functionality
49
+ . " $GITFLOW_DIR /gitflow-common"
50
+
56
51
# use the shFlags project to parse the command line arguments
57
- . " $GITFLOW_DIR /shFlags.sh "
52
+ . " $GITFLOW_DIR /gitflow- shFlags"
58
53
FLAGS_PARENT=" git flow"
59
- # DEFINE_boolean quiet 0 'run without output' q
60
- # DEFINE_boolean verbose 0 'run verbose (more output)' v
61
54
FLAGS " $@ " || exit $?
62
55
eval set -- " ${FLAGS_ARGV} "
63
56
@@ -73,11 +66,6 @@ main() {
73
66
die " Not a git repository"
74
67
fi
75
68
76
- # get all available branches
77
- LOCAL_BRANCHES=$( git branch | sed ' s/^[* ] //' )
78
- REMOTE_BRANCHES=$( git branch -r | sed ' s/^[* ] //' )
79
- ALL_BRANCHES=" $LOCAL_BRANCHES $REMOTE_BRANCHES "
80
-
81
69
# run command
82
70
. " $GITFLOW_DIR /git-flow-$SUBCOMMAND "
83
71
FLAGS_PARENT=" git flow $SUBCOMMAND "
@@ -99,109 +87,6 @@ main() {
99
87
cmd_$SUBACTION " $@ "
100
88
}
101
89
102
- gitflow_test_clean_working_tree () {
103
- if ! git diff --no-ext-diff --ignore-submodules --quiet --exit-code; then
104
- return 1
105
- elif ! git diff-index --cached --quiet --ignore-submodules HEAD --; then
106
- return 2
107
- else
108
- return 0
109
- fi
110
- }
111
-
112
- gitflow_require_clean_working_tree () {
113
- gitflow_test_clean_working_tree
114
- result=$?
115
- if [ $result -eq 1 ]; then
116
- die " fatal: Working tree contains unstaged changes. Aborting."
117
- fi
118
- if [ $result -eq 2 ]; then
119
- die " fatal: Index contains uncommited changes. Aborting."
120
- fi
121
- }
122
-
123
- gitflow_require_local_branch () {
124
- if ! has $1 $LOCAL_BRANCHES ; then
125
- die " fatal: Local branch '$1 ' does not exist and is required."
126
- fi
127
- }
128
-
129
- gitflow_require_remote_branch () {
130
- if ! has $1 $REMOTE_BRANCHES ; then
131
- die " Remote branch '$1 ' does not exist and is required."
132
- fi
133
- }
134
-
135
- gitflow_require_branch () {
136
- if ! has $1 $ALL_BRANCHES ; then
137
- die " Branch '$1 ' does not exist and is required."
138
- fi
139
- }
140
-
141
- gitflow_require_branch_absent () {
142
- if has $1 $ALL_BRANCHES ; then
143
- die " Branch '$1 ' already exists. Pick another name."
144
- fi
145
- }
146
-
147
- #
148
- # gitflow_test_branches_equal()
149
- #
150
- # Tests whether branches and their "origin" counterparts have diverged and need
151
- # merging first. It returns error codes to provide more detail, like so:
152
- #
153
- # 0 Branch heads point to the same commit
154
- # 1 First given branch needs fast-forwarding
155
- # 2 Second given branch needs fast-forwarding
156
- # 3 Branch needs a real merge
157
- #
158
- gitflow_test_branches_equal () {
159
- commit1=$( git rev-parse " $1 " )
160
- commit2=$( git rev-parse " $2 " )
161
- if [ " $commit1 " != " $commit2 " ]; then
162
- base=$( git merge-base " $commit1 " " $commit2 " )
163
- if [ " $commit1 " = " $base " ]; then
164
- return 1
165
- elif [ " $commit2 " = " $base " ]; then
166
- return 2
167
- else
168
- return 3
169
- fi
170
- else
171
- return 0
172
- fi
173
- }
174
-
175
- gitflow_require_branches_equal () {
176
- gitflow_require_local_branch " $1 "
177
- gitflow_require_remote_branch " $2 "
178
- gitflow_test_branches_equal " $1 " " $2 "
179
- status=$?
180
- if [ $status -gt 0 ]; then
181
- warn " Branches '$1 ' and '$2 ' have diverged."
182
- if [ $status -eq 1 ]; then
183
- die " And branch '$1 ' may be fast-forwarded."
184
- elif [ $status -eq 2 ]; then
185
- # Warn here, since there is no harm in being ahead
186
- warn " And local branch '$1 ' is ahead of '$2 '."
187
- else
188
- die " Branches need merging first."
189
- fi
190
- fi
191
- }
192
-
193
- #
194
- # gitflow_is_branch_merged_into()
195
- #
196
- # Checks whether branch $1 is succesfully merged into $2
197
- #
198
- gitflow_is_branch_merged_into () {
199
- local SUBJECT=$1
200
- local BASE=$2
201
- ALL_MERGES=$( git branch --contains $SUBJECT | sed ' s/^[* ] //' )
202
- has $BASE $ALL_MERGES
203
- }
204
-
205
90
# helper functions for common reuse
206
91
max () { if [ " $1 " -gt " $2 " ]; then echo " $1 " ; else echo " $2 " ; fi ; }
207
92
0 commit comments