Class: PodsOrz::PodsGitOperator

Inherits:
Object
  • Object
show all
Defined in:
lib/podsorz/core/PodsOrz/pods_git_operator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kx_pods_path, app_release_version, author_suffix) ⇒ PodsGitOperator

Returns a new instance of PodsGitOperator.



9
10
11
12
13
14
15
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 9

def initialize(kx_pods_path, app_release_version, author_suffix)
	@kx_pods_path = kx_pods_path
	@app_release_version = app_release_version
	@author_suffix = author_suffix

	@git_operator = PodsOrz::GitOperator.new()
end

Instance Attribute Details

#app_release_versionObject

Returns the value of attribute app_release_version.



7
8
9
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 7

def app_release_version
  @app_release_version
end

#author_suffixObject

Returns the value of attribute author_suffix.



7
8
9
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 7

def author_suffix
  @author_suffix
end

#git_operatorObject

Returns the value of attribute git_operator.



7
8
9
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 7

def git_operator
  @git_operator
end

#kx_pods_pathObject

Returns the value of attribute kx_pods_path.



7
8
9
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 7

def kx_pods_path
  @kx_pods_path
end

Instance Method Details

#add_pod_tag(pod, version_num) ⇒ Object



555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 555

def add_pod_tag(pod, version_num)
	is_add_success = true
	pod_file_path = File.expand_path(pod, @kx_pods_path)

	tag_list = @git_operator.tag_list(pod_file_path)

	has_tag = false
	tag_list.each do |tag|
		has_tag = true if tag.to_s.include? version_num
	end

	if has_tag
		Logger.error("\'#{pod}\' -> #{version_num} git tag is exist, please increase #{pod}.podspec version number")
		is_add_success = false
		return is_add_success
	end

	tag_cmd_list = []
	tag_cmd_list << "cd #{pod_file_path}"
	tag_cmd_list << "git tag #{version_num}"
	tag_cmd_list << "git push origin #{version_num}"
	IO.popen(tag_cmd_list.join(";")) do |io|
		io.each do |line|
			puts line
		end

		Logger.highlight("\'#{pod}\' -> :#{version_num} tag add success")
		io.close
	end

	is_add_success

end

#check_prepare_work(pod) ⇒ Object



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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 170

def check_prepare_work(pod)
	is_ready = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	has_changes = @git_operator.has_changes(pod_file_path)
	if has_changes
		Logger.error("#{pod}】 on branch: \"#{current_branch}\" has unstaged/uncommit changes, please staged and commit local first")
		is_ready = false

		return is_ready
	end


	has_commits_unpush = false
	has_remote_branch = @git_operator.has_remote_branch(pod_file_path, current_branch)
	unless has_remote_branch
		Logger.warning("#{pod}】 on branch: \'#{current_branch}\' is local branch, please do not forget to push remote in future.") 	
	else
		check_cmd_list = []
		check_cmd_list << "cd #{pod_file_path}"
		check_cmd_list << "git log --left-right #{current_branch}...origin/#{current_branch} --pretty=oneline"
		io_lines = []
		local_commits = []
	    IO.popen(check_cmd_list.join(";")) do |io|
	    	io_lines = io.readlines
	    	io_lines.each do |line|
	        	if line.include? "<"
	        		has_commits_unpush = true 
	        		local_commits << line
	        	end
	        end

	        io.close
	    end

		if has_commits_unpush
			Logger.separator
			local_commits.each do |line|
				puts line
			end
			Logger.separator

			is_develop = current_branch.include? "develop"
			is_release = current_branch.include? "release/"
			if is_develop || is_release
				Logger.error("#{pod}】on branch: \'#{current_branch}\' forbidden local commit which will be ‘reset --hard’ by other operation.Please manual 'git checkout #{current_branch};git push' first")
				is_ready = false
			else
				Logger.warning("#{pod}】on branch: \'#{current_branch}\' has local commits that not push remote, please do not forget to push remote in future.")
			end
			
		end
	end

	is_ready
end

#clear_modify_pod(pod) ⇒ Object



413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 413

def clear_modify_pod(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	clear_cmd_list = []
	clear_cmd_list << "cd #{pod_file_path}"
	clear_cmd_list << "git checkout ."
	IO.popen(clear_cmd_list.join(";")) do |io|
		Logger.default("#{pod} on branch is clear")
		io.close
	end
end

#commit_local(pod) ⇒ Object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 276

def commit_local(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	has_changes = @git_operator.has_changes(pod_file_path)
	if has_changes
		Logger.default("请输入【#{pod}】提交的message备注:")
		message = gets
		message = "#{@author_suffix} 默认提交信息" if message.strip.empty?

		@git_operator.commit(pod_file_path, message)
	else
		current_branch = self.current_pod_branch(pod)
		Logger.default("#{pod}】 on branch: \"#{current_branch}\" nothing to commit.")
	end
end

#commit_notify(pod) ⇒ Object



314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 314

def commit_notify(pod)
	is_push_success = true

	current_branch = self.current_pod_branch(pod)

	#develop & release push remote
	is_develop = current_branch.include? "develop"
	is_release = current_branch.include? "release"

	if is_develop || is_release
		
	end

	#feature
	is_feature = current_branch.include? "feature"
	if is_feature
		is_push_success = self.commit_notify_persional_branch(pod, "develop")
	end

	#bugfix
	is_bugfix = current_branch.include? "bugfix"
	if is_bugfix
		is_push_success = self.commit_notify_persional_branch(pod, "release")
	end
	
	is_push_success
end

#commit_notify_persional_branch(pod, parent_branch) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 342

def commit_notify_persional_branch(pod, parent_branch)
	base_on_branch = ""
	if parent_branch.include? "develop"
		base_on_branch = "develop"
	else
		base_on_branch = "release/" + "#{@app_release_version}"
	end

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)
	is_push_success = true
	is_rebase_success = @git_operator.rebase(pod_file_path, base_on_branch)

	unless is_rebase_success
		Logger.error("#{pod}】 on branch: \"#{current_branch}\" Merge conflict, please manual fix conflicts.(fix conflicts and run \"git rebase --continue\")(use \"git rebase --abort\" to abort the merge)")
		is_push_success = false
	else
		force_push_cmd_list = []
		force_push_cmd_list << "cd #{pod_file_path}"
		force_push_cmd_list << "git push -f -u origin #{current_branch}"
		IO.popen(force_push_cmd_list.join(";")) do |io|
			io.each do |line|
				puts line
			end

			Logger.highlight("#{pod}】 on branch: \"#{current_branch}\" push remote success")
			io.close
		end

		merge_cmd_list = []
		merge_cmd_list << "cd #{pod_file_path}"
		merge_cmd_list << "git checkout #{base_on_branch}"
		merge_cmd_list << "git merge #{current_branch} --no-ff --no-squash --no-edit"
		merge_cmd_list << "git push -u origin #{base_on_branch}"
		IO.popen(merge_cmd_list.join(";")) do |io|
			io.each do |line|
				puts line
			end

			Logger.highlight("#{pod}】 on branch: \"#{current_branch}\" Merge into #{base_on_branch} success")
			io.close
		end

		local_branch_cmd_list = []
		local_branch_cmd_list << "cd #{pod_file_path}"
		local_branch_cmd_list << "git checkout #{current_branch}"
		local_branch_cmd_list << "git push origin --delete #{current_branch}"

		IO.popen(local_branch_cmd_list.join(";")) do |io|
			io.each do |line|
				puts line
			end

			Logger.highlight("#{pod}】 on branch: \"#{current_branch}\" has deleted remote branch")
			io.close
		end
	end

	return is_push_success
end

#commit_push(pod) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 291

def commit_push(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	is_push_success = true

	has_remote_branch = @git_operator.has_remote_branch(pod_file_path, current_branch)
	unless has_remote_branch
		is_push_success = @git_operator.push_to_remote(pod_file_path, current_branch)
		return is_push_success
	end

	is_pull_success = @git_operator.pull(pod_file_path, current_branch, false)

	if is_pull_success
		is_push_success = @git_operator.push_to_remote(pod_file_path, current_branch)
	else
		is_push_success = false
	end

	is_push_success
end

#commit_version_increase(pod, version) ⇒ Object



403
404
405
406
407
408
409
410
411
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 403

def commit_version_increase(pod, version)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	message = "#{pod} version increase to \'#{version}\'"
	@git_operator.commit(pod_file_path, message)

	is_commit_success = self.commit_push(pod)

	is_commit_success
end

#current_pod_branch(pod) ⇒ Object



163
164
165
166
167
168
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 163

def current_pod_branch(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	branch = @git_operator.current_branch(pod_file_path)

	branch
end

#delete_pod_tag(pod, version_num) ⇒ Object



589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 589

def delete_pod_tag(pod, version_num)
	is_delete_success = true
	pod_file_path = File.expand_path(pod, @kx_pods_path)

	tag_list = @git_operator.tag_list(pod_file_path)
	has_tag = false
	tag_list.each do |tag|
		has_tag = true if tag.to_s.include? version_num
	end

	unless has_tag
		Logger.warning("#{tag_list}, #{version_num}    delete			1")
		Logger.warning("\'#{pod}\' -> #{version_num} git tag is not exist, nothing needs to delete")
		return is_delete_success
	end

	tag_cmd_list = []
	tag_cmd_list << "cd #{pod_file_path}"
	tag_cmd_list << "git tag -d #{version_num}"
	tag_cmd_list << "git push origin -d #{version_num}"
	IO.popen(tag_cmd_list.join(";")) do |io|
		io.each do |line|
			puts line
		end

		Logger.highlight("\'#{pod}\' -> :#{version_num} tag delete success")
		io.close
	end

	is_delete_success
end

#double_check_personal_rebase_fore_push(pod) ⇒ Object



897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 897

def double_check_personal_rebase_fore_push(pod)
	is_check_success = true
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	Logger.warning("#{pod}】本地分支:#{current_branch} rebase后与远端分支origin/#{current_branch}存在分叉,是否以本地分支'强推'覆盖远端分支,请选择输入:[force / wait]")
	force_input = gets
	if force_input.downcase.include? "wait"
		Logger.warning("取消强推后,需要自行手动'git push -f'提交代码 or 'git reset commit'回退版本,请个人处理分支情况")
		return is_check_success
	end

	unless force_input.downcase.include? "force"
		is_check_success = double_check_personal_rebase_fore_push(pod)
		return is_check_success
	end

	#push -f
	is_check_success = @git_operator.push_personal_force_to_remote(pod_file_path, current_branch)
	
	is_check_success
end

#ensure_develop_branch(pod) ⇒ Object



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 229

def ensure_develop_branch(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	has_branch = @git_operator.has_branch(pod_file_path, "develop")
	current_branch = self.current_pod_branch(pod)

	if !has_branch
		#develop new
		Logger.warning("\"#{pod}\" do not have develop branch, current branch is: \"#{current_branch}\", generate develop...")

		develop_cmd_list = []
		develop_cmd_list << "cd #{pod_file_path}"
		develop_cmd_list << "git checkout master" unless current_branch.include? "master"
		develop_cmd_list << "git fetch origin master"
		develop_cmd_list << "git reset --hard origin/master"
		develop_cmd_list << "git checkout -b develop"
		develop_cmd_list << "git push -u origin develop"

		io_lines = []
		IO.popen(develop_cmd_list.join(";")) do |io|
			io_lines = io.readlines
			io_lines.each do |line|
				puts line
			end
			io.close
		end

	else 
		#fetch develop force
		Logger.warning("\"#{pod}\" needs to ensure develop latest, forced!")

		develop_cmd_list = []
		develop_cmd_list << "cd #{pod_file_path}"
		develop_cmd_list << "git checkout develop" unless current_branch.include? "develop"
		develop_cmd_list << "git fetch origin develop"
		develop_cmd_list << "git reset --hard origin/develop"

		io_lines = []
		IO.popen(develop_cmd_list.join(";")) do |io|
			io_lines = io.readlines
			io_lines.each do |line|
				puts line
			end
			io.close
		end
	end
end

#get_pod_file_path(pod) ⇒ Object



17
18
19
20
21
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 17

def get_pod_file_path(pod)
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	
	pod_file_path
end

#get_pod_git_tag(pod) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 621

def get_pod_git_tag(pod)
	git_tag = "0.0.0"

	pod_file_path = File.expand_path(pod, @kx_pods_path)

	tag_list = @git_operator.tag_list(pod_file_path)
	
	return git_tag if tag_list.empty?

	git_tag = tag_list.first.to_s

	git_tag
end

#has_new_publish(pod, branch_name) ⇒ Object

Publish



428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 428

def has_new_publish(pod, branch_name)
	is_new_content = true

	is_new_content = is_publish_ready(pod)
	return is_new_content unless is_new_content


	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	fetch_cmd_list = []
	fetch_cmd_list << "cd #{pod_file_path}"
	fetch_cmd_list << "git fetch origin #{branch_name}"
	IO.popen(fetch_cmd_list.join(";")) do |io|
			io.each do |line|
				puts line
			end
			io.close
	end

	diff_lines_list = []
	diff_lines_list = @git_operator.compare_branch(pod_file_path, current_branch, "origin/#{branch_name}")

	if diff_lines_list.empty?
		is_new_content = false 
		return is_new_content
	end

	#filter Merge branch
	diff_lines_list.delete_if {|item|
		item.to_s.include? "Merge branch"
	}
	
	is_new_content = false

	Logger.warning("#{pod} on branch:\'#{current_branch}\' -- compare branch:\'origin/#{branch_name}\'")

	should_show_detail = true
	limit_count = 10

	if diff_lines_list.size > limit_count
		Logger.default("不同 commit 较多,是否显示全部 commit ?选择输入:[yes / no]") 
		input_choose = gets
		unless input_choose.downcase.include? "yes"
			should_show_detail = false
		end
	end
	
	diff_lines_list.each do |line|
		limit_count = limit_count -1 unless should_show_detail

		puts line if limit_count >= 0

		is_new_content = true if line.strip.chomp.include? "<"
	end

	is_new_content
end

#is_publish_ready(pod) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 487

def is_publish_ready(pod)
	is_ready = true

	#has un-staged un-cached
	is_ready = check_prepare_work(pod)
	return is_ready unless is_ready
	
	#fetch latest
	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	unless current_branch.include? "release"
		Logger.error("#{pod}】current branch: #{current_branch}, is not release branch!")
		is_ready = false
		return is_ready
	end

	is_ready
end

#publish_merge(pod, merge_into_branch) ⇒ Object



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 507

def publish_merge(pod, merge_into_branch)
	is_merge_success = true
	
	is_merge_success = is_publish_ready(pod)
	return is_merge_success unless is_merge_success

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = self.current_pod_branch(pod)

	fetch_cmd_list = []
	fetch_cmd_list << "cd #{pod_file_path}"
	fetch_cmd_list << "git fetch origin #{current_branch}"
	fetch_cmd_list << "git reset --hard origin/#{current_branch}"
	IO.popen(fetch_cmd_list.join(";")) do |io|
		io.each do |line|
			puts line
		end
		io.close
	end

	is_merge_success = publish_merge_branch(pod, merge_into_branch, current_branch)

	is_merge_success
end

#publish_merge_branch(pod, into_branch, from_branch) ⇒ Object



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 532

def publish_merge_branch(pod, into_branch, from_branch)
	is_merge_success = true
	pod_file_path = File.expand_path(pod, @kx_pods_path)

	is_merge_success = @git_operator.merge(pod_file_path, into_branch, from_branch)
	return is_merge_success unless is_merge_success

	push_cmd_list = []
	push_cmd_list << "cd #{pod_file_path}"
	push_cmd_list << "git push -u origin #{into_branch}"
	push_cmd_list << "git checkout #{from_branch}"
	IO.popen(push_cmd_list.join(";")) do |io|
		io.each do |line|
			puts line
		end

		Logger.highlight("#{pod}】from:#{from_branch} merge into branch: #{into_branch} success")
		io.close
	end

	is_merge_success
end

#switch_bugfix_pod(pod) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 117

def switch_bugfix_pod(pod)
	previous_branch = self.current_pod_branch(pod)
	next_branch = "bugfix/" + "#{@author_suffix}"

	is_ready = true
	is_same = previous_branch.include? next_branch
	if !is_same
		#diff branch
		is_ready = check_prepare_work(pod)
		if is_ready
			pod_file_path = File.expand_path(pod, @kx_pods_path)
			has_branch = @git_operator.has_branch(pod_file_path, next_branch)
			if has_branch
				@git_operator.checkout(pod_file_path, next_branch)
			else
				#bugfix new
				release_branch = "release/" + "#{@app_release_version}"
				has_release_branch = @git_operator.has_branch(pod_file_path, release_branch)
				if has_release_branch
					bugfix_cmd_list = []
					bugfix_cmd_list << "cd #{pod_file_path}"
					bugfix_cmd_list << "git checkout #{release_branch}" unless previous_branch.include? release_branch
					bugfix_cmd_list << "git fetch origin #{release_branch}"
					bugfix_cmd_list << "git reset --hard origin/#{release_branch}"
					bugfix_cmd_list << "git checkout -b #{next_branch}"

					io_lines = []
					IO.popen(bugfix_cmd_list.join(";")) do |io|
						io_lines = io.readlines
						io_lines.each do |line|
							puts line
						end
						io.close
					end
				else
					Logger.error("#{pod}】not exist release branch: #{release_branch}")
					is_ready = false
				end
			end
			
		end
	end

	is_ready
end

#switch_develop_pod(pod) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 23

def switch_develop_pod(pod)
	previous_branch = self.current_pod_branch(pod)
	next_branch = "develop"

	is_ready = true
	is_same = previous_branch.include? next_branch
	if !is_same
		#diff branch
		is_ready = check_prepare_work(pod)
		if is_ready
			#switch to develop, auto fetch latest
			self.ensure_develop_branch(pod)
		end
	end

	is_ready
end

#switch_feature_pod(pod) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 41

def switch_feature_pod(pod)
	previous_branch = self.current_pod_branch(pod)
	next_branch = "feature/" + "#{@author_suffix}"

	is_ready = true
	is_same = previous_branch.include? next_branch
	if !is_same
		#diff branch
		is_ready = check_prepare_work(pod)
		if is_ready
			pod_file_path = File.expand_path(pod, @kx_pods_path)
			has_branch = @git_operator.has_branch(pod_file_path, next_branch)
			if has_branch
				@git_operator.checkout(pod_file_path, next_branch)
			else
				#feature new
				self.ensure_develop_branch(pod)

				feature_cmd_list = []
				feature_cmd_list << "cd #{pod_file_path}"
				feature_cmd_list << "git checkout -b #{next_branch}"

				io_lines = []
				IO.popen(feature_cmd_list.join(";")) do |io|
					io_lines = io.readlines
					io_lines.each do |line|
						puts line
					end
					io.close
				end
			end
			
		end
	end

	is_ready
end

#switch_release_pod(pod) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 79

def switch_release_pod(pod)
	previous_branch = self.current_pod_branch(pod)
	next_branch = "release/" + "#{@app_release_version}"

	is_ready = true
	is_same = previous_branch.include? next_branch
	if !is_same
		#diff branch
		is_ready = check_prepare_work(pod)
		if is_ready
			pod_file_path = File.expand_path(pod, @kx_pods_path)
			has_branch = @git_operator.has_branch(pod_file_path, next_branch)
			if has_branch
				@git_operator.checkout(pod_file_path, next_branch)
			else
				#release new
				self.ensure_develop_branch(pod)

				release_cmd_list = []
				release_cmd_list << "cd #{pod_file_path}"
				release_cmd_list << "git checkout -b #{next_branch}"
				release_cmd_list << "git push -u origin #{next_branch}"

				io_lines = []
				IO.popen(release_cmd_list.join(";")) do |io|
					io_lines = io.readlines
					io_lines.each do |line|
						puts line
					end
					io.close
				end
			end
		end
	end

	is_ready
end

#sync_current_branch_pull(pod) ⇒ Object



673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 673

def sync_current_branch_pull(pod)
	is_pull_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	has_remote_branch = @git_operator.has_remote_branch(pod_file_path, current_branch)
	if has_remote_branch
		is_pull_success = @git_operator.pull(pod_file_path, current_branch, false)
	end
	
	is_pull_success
end

#sync_parent_rebase(pod, rebase_branch) ⇒ Object



784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 784

def sync_parent_rebase(pod, rebase_branch)
	is_rebase_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	Logger.default("#{pod}】 current_branch:#{current_branch} --rebase=#{rebase_branch} start...") 

	#0.fetch origin develop
	@git_operator.fetch(pod_file_path, rebase_branch)

	diff_commit_lines = @git_operator.compare_branch(pod_file_path, current_branch, "origin/#{rebase_branch}")

	unless diff_commit_lines.empty?
		Logger.warning("#{pod}】has diff commits between '#{current_branch}'-'#{rebase_branch}':\n")
		diff_commit_lines.each do |line|
			puts(line)
		end
	end

	is_develop_has_commit = false
	is_release_has_commit = false

	diff_commit_lines.each do |line|
		is_develop_has_commit = true if line.include? ">"
		is_release_has_commit = true if line.include? "<"
	end

	#1.release only
	if is_release_has_commit && !is_develop_has_commit
		Logger.highlight("#{pod}】:#{current_branch} already has totoal commits from 'develop'")
		return(is_rebase_success)
	end
	
	#2.develop only
	if !is_release_has_commit && is_develop_has_commit
		is_rebase_success = @git_operator.rebase(pod_file_path, rebase_branch)

		if is_rebase_success
			is_rebase_success = @git_operator.push_to_remote(pod_file_path, current_branch)
		end

		Logger.highlight("#{pod}】:#{current_branch} sync commits from 'develop' completed!") if is_rebase_success

		return(is_rebase_success)
	end

	#3.release,develop diff each other
	#3.1 Merge 
	is_rebase_success = @git_operator.merge(pod_file_path, rebase_branch, current_branch)
	unless is_rebase_success
		todo_desc = %{
			CMD on 【#{pod}】 sync --rebase=develop failure!

			1.fix develop merge #{current_branch} conflicts.
			2.'push' develop merged code to remote 
			3.checkout #{current_branch} ,rebase 'develop' 
			4.#{current_branch} push to remote
		}
		Logger.error("#{todo_desc}")
		return is_rebase_success 
	end

	#3.2 Push develop
	is_rebase_success = @git_operator.push_to_remote(pod_file_path, rebase_branch)
	return is_rebase_success unless is_rebase_success

	Logger.highlight("#{pod}】:'develop' merged commits from '#{current_branch}' completed!")

	#3.3 Rebase develop
	is_rebase_success = @git_operator.checkout(pod_file_path, current_branch)
	return(is_rebase_success) unless is_rebase_success

	is_rebase_success = @git_operator.rebase(pod_file_path, rebase_branch)
	return(is_rebase_success) unless is_rebase_success

	Logger.highlight("#{pod}】:'#{current_branch}' sync commits from 'develop' completed!")

	#3.4 Push current to remote
	is_rebase_success = @git_operator.push_to_remote(pod_file_path, current_branch)
	return(is_rebase_success) unless is_rebase_success

	Logger.highlight("#{pod}】:'#{current_branch}' && 'develop' stand at the same starting line!")

	is_rebase_success			
end

#sync_personal_rebase(pod, rebase_branch) ⇒ Object



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 871

def sync_personal_rebase(pod, rebase_branch)
	is_rebase_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	Logger.default("#{pod}】 current_branch:#{current_branch} --rebase=#{rebase_branch} start...") 
	p_rebase_success = @git_operator.rebase(pod_file_path, rebase_branch)

	unless p_rebase_success
		is_rebase_success = false
		Logger.warning("#{pod}】--rebase=#{rebase_branch} 冲突,请手动解决冲突,并且进行后续强推个人分支操作('git push -f -u orogin #{current_branch}')。切勿反复调用 podsorz sync --rebase=#{rebase_branch} 带来未知情况的错误")
		return is_rebase_success
	end

	#Personal branch diverged
	has_div = @git_operator.has_diverged(pod_file_path)
	if has_div
		is_rebase_success = double_check_personal_rebase_fore_push(pod)
	else
		Logger.highlight("#{pod}】 current_branch:#{current_branch} --rebase=#{rebase_branch} completed, use 'podsorz commit --push --notify' to push & notify updated code, or 'git reset commit' roll back to old version")
	end

	is_rebase_success
end

#sync_pod(pod, rebase_branch) ⇒ Object

sync cmd



637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 637

def sync_pod(pod, rebase_branch)
	is_sync_success = true

	is_ready = check_prepare_work(pod)
	unless is_ready
		is_sync_success = false
		return is_sync_success
	end

	#pull
	is_pull_success = sync_current_branch_pull(pod)
	unless is_pull_success
		is_sync_success = false
		return is_sync_success
	end
	
	#rebase
	rebase_branch = rebase_branch.strip.chomp
	return is_sync_success if rebase_branch.nil?
	return is_sync_success if rebase_branch.empty?

	is_prepare_rebase = sync_prepare_rebase(pod, rebase_branch)
	unless is_prepare_rebase
		is_sync_success = false
		return is_sync_success
	end

	is_rebase_success = sync_rebase(pod, rebase_branch)
	unless is_rebase_success
		is_sync_success = false
		return is_sync_success
	end

	is_sync_success
end

#sync_prepare_rebase(pod, rebase_branch) ⇒ Object



687
688
689
690
691
692
693
694
695
696
697
698
699
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 687

def sync_prepare_rebase(pod, rebase_branch)
	is_check_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	has_branch = @git_operator.has_branch(pod_file_path, rebase_branch)
	unless has_branch
		Logger.error("branch '#{rebase_branch}' is not exist")
		is_check_success = false
		return is_check_success
	end

	is_check_success
end

#sync_rebase(pod, rebase_branch) ⇒ Object



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 701

def sync_rebase(pod, rebase_branch)
	is_rebase_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	is_rebase_branch_check = sync_rebase_branch_check(pod, rebase_branch)
	unless is_rebase_branch_check
		is_rebase_success = false
		return is_rebase_success
	end

	is_current_release_branch = current_branch.include? "release"

	if is_current_release_branch
		#release
		is_rebase_success = sync_parent_rebase(pod, rebase_branch)
	else
		#personal
		is_rebase_success = sync_personal_rebase(pod, rebase_branch)
	end

	is_rebase_success
end

#sync_rebase_branch_check(pod, rebase_branch) ⇒ Object



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'lib/podsorz/core/PodsOrz/pods_git_operator.rb', line 726

def sync_rebase_branch_check(pod, rebase_branch)
	is_check_success = true

	pod_file_path = File.expand_path(pod, @kx_pods_path)
	current_branch = @git_operator.current_branch(pod_file_path)

	#1.except develop
	is_inlcude = current_branch.include? "develop"
	if is_inlcude
		Logger.error("CMD of sync which current_branch can't be 'develop','develop' not support --rebase")
		is_check_success = false
		return is_check_success
	end

	#2.release_branch can only rebase develop
	is_current_release_branch = current_branch.include? "release"
	if is_current_release_branch
		is_inlcude = rebase_branch.include? "develop"
		unless is_inlcude
			Logger.error("current_branch:#{current_branch} can only rebase 'develop', rebase_branch:#{rebase_branch} not support!")
			is_check_success = false
			return is_check_success
		end
	end

	#3.except rebase myself
	is_inlcude = current_branch.include? rebase_branch
	if is_inlcude
		Logger.error("CMD of sync which current_branch :#{current_branch} can't --rebase itself ")
		is_check_success = false
		return is_check_success
	end

	#4.feature & bugfix
	is_feature_branch = current_branch.include? "feature"
	if is_feature_branch
		is_rebase_branch_develop = rebase_branch.include? "develop"
		unless is_rebase_branch_develop
			Logger.error("CMD of sync which current_branch :#{current_branch} can only --rebase=develop")
			is_check_success = false
			return is_check_success
		end
	end

	is_bugfix_branch = current_branch.include? "bugfix"
	if is_bugfix_branch
		is_rebase_branch_release = rebase_branch.include? "release"
		unless is_rebase_branch_release
			Logger.error("CMD of sync which current_branch :#{current_branch} can only --rebase='release_xxxx'")
			is_check_success = false
			return is_check_success
		end
	end


	is_check_success
end