class PodsOrz::PodsGitOperator

Attributes

app_release_version[RW]
author_suffix[RW]
git_operator[RW]
kx_pods_path[RW]

Public Class Methods

new(kx_pods_path, app_release_version, author_suffix) click to toggle source
# 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

Public Instance Methods

add_pod_tag(pod, version_num) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Publish

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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}" + "_#{@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
                                #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) click to toggle source
# 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) click to toggle source
# 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}" + "_#{@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
                                #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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

sync cmd

# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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