131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/pindo/command/dev/tag.rb', line 131
def merge_to_release_branch(project_dir: nil, release_branch: nil, coding_branch: nil)
current_project_dir = project_dir
Funlog.instance.fancyinfo_start("开始合并到#{release_branch}分支")
if !coding_branch.eql?(release_branch)
coding_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{coding_branch})).strip
release_branch_commit_id = nil
if remote_branch_exists?(local_repo_dir: current_project_dir, branch: release_branch)
Funlog.instance.fancyinfo_update("存在#{release_branch}远程分支")
if local_branch_exists?(local_repo_dir: current_project_dir, branch: release_branch)
Funlog.instance.fancyinfo_update("存在#{release_branch}本地分支")
git!(%W(-C #{current_project_dir} checkout #{release_branch}))
else
Funlog.instance.fancyinfo_update("不存在#{release_branch}本地分支")
git!(%W(-C #{current_project_dir} checkout -b #{release_branch} origin/#{release_branch}))
end
git!(%W(-C #{current_project_dir} branch --set-upstream-to=origin/#{release_branch} #{release_branch}))
git!(%W(-C #{current_project_dir} fetch origin #{release_branch}))
git!(%W(-C #{current_project_dir} merge origin/#{release_branch}))
stdout, exit_status = Executable.capture_command('git', %W(-C #{current_project_dir} merge #{coding_branch}), :capture => :out)
conflict_filelist = git!(%W(-C #{current_project_dir} diff --name-only --diff-filter=U --relative))
if !conflict_filelist.nil? && conflict_filelist.size > 0
puts "合并代码冲突, 冲突文件如下:"
raise Informative, "请手动处理冲突的文件!!!"
else
git!(%W(-C #{current_project_dir} push))
Funlog.instance.fancyinfo_success("代码已经合并到#{release_branch}分支")
begin
release_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{release_branch})).strip
rescue => e
Funlog.instance.fancyinfo_update("#{release_branch}分支为空或获取commit失败,将使用当前分支commit")
release_branch_commit_id = coding_branch_commit_id
end
end
else
if local_branch_exists?(local_repo_dir: current_project_dir, branch: release_branch)
Funlog.instance.fancyinfo_update("不存在#{release_branch}远程分支")
Funlog.instance.fancyinfo_update("存在#{release_branch}本地分支")
git!(%W(-C #{current_project_dir} checkout #{release_branch}))
git!(%W(-C #{current_project_dir} checkout -b #{release_branch}_temp))
git!(%W(-C #{current_project_dir} checkout #{coding_branch}))
git!(%W(-C #{current_project_dir} branch -D #{release_branch}))
else
Funlog.instance.fancyinfo_update("不存在#{release_branch}远程分支")
Funlog.instance.fancyinfo_update("不存在#{release_branch}本地分支")
end
git!(%W(-C #{current_project_dir} checkout -b #{release_branch}))
git!(%W(-C #{current_project_dir} push origin #{release_branch}))
git!(%W(-C #{current_project_dir} branch --set-upstream-to=origin/#{release_branch} #{release_branch}))
Funlog.instance.fancyinfo_success("代码已经合并到#{release_branch}分支")
begin
release_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{release_branch})).strip
rescue => e
release_branch_commit_id = coding_branch_commit_id
end
end
git!(%W(-C #{current_project_dir} checkout #{coding_branch}))
if release_branch_commit_id && !release_branch_commit_id.eql?(coding_branch_commit_id)
git!(%W(-C #{current_project_dir} merge #{release_branch}))
Funlog.instance.fancyinfo_success("已将#{release_branch}合并到#{coding_branch}")
end
git!(%W(-C #{current_project_dir} push origin #{coding_branch}))
Funlog.instance.fancyinfo_success("已推送#{coding_branch}分支到远程")
else
Funlog.instance.fancyinfo_success("代码处于#{coding_branch}分支,无需合并")
end
end
|