lib/ComponentSynchronizer.rb in pixab-1.8.1 vs lib/ComponentSynchronizer.rb in pixab-1.9.0

- old
+ new

@@ -2,25 +2,27 @@ # encoding: UTF-8 require "fileutils" require 'colored2' require 'open3' -require_relative './Utilities.rb' +require_relative './GitUtils.rb' require_relative './RepoManager.rb' module Pixab class ComponentSynchronizer - attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install + attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install, :is_use__target_branch attr_reader :repo_manager, :repos, :main_repo_name, :updated_repo_names def initialize(repo_manager = RepoManager.new, commands = nil) @repo_manager = repo_manager @is_need_build = false @is_need_remote_repo = false @is_need_pod_install = true + @is_use__target_branch = true + if commands.nil? return end commands.each_index do |index| command = commands[index] @@ -29,13 +31,16 @@ @is_need_build = true when "--remote-repo" @is_need_remote_repo = true when "--no-pod-install" @is_need_pod_install = false + when "--current-branch" + @is_use__target_branch = false else end end + end def run read_repo_infos @@ -119,13 +124,18 @@ def replace_podfile # 获取每个子库最新的commit id repo_commite_id = {} repos.each do |repo| repo_name = repo["name"] - repo_target_branch = repo["target_branch"] + FileUtils.cd("#{repo_manager.root_path}/#{repo_name}") - `git fetch origin #{repo_target_branch}` + repo_target_branch = @is_use__target_branch ? repo_target_branch = repo["target_branch"] : GitUtils.current_branch + next unless GitUtils.check_remote_branch_exists_fast("origin/#{repo_target_branch}") + + stdout, status = Open3.capture2("git fetch origin #{repo_target_branch}") + next unless status.success? + commit_id = `git log origin/#{repo_target_branch} -n 1 --pretty=format:"%H"` if !commit_id.nil? repo_commite_id[repo_name] = commit_id end end @@ -197,7 +207,6 @@ Utilities.check_shell_result("Error: xcode build failed") end end -end - +end \ No newline at end of file