Class: Pindo::Command::Lib::Forcepush
- Inherits:
-
Pindo::Command::Lib
- Object
- CLAide::Command
- Pindo::Command
- Pindo::Command::Lib
- Pindo::Command::Lib::Forcepush
- Defined in:
- lib/pindo/command/lib/forcepush.rb
Constant Summary
Constants inherited from Pindo::Command
DEFAULT_OPTIONS, DEFAULT_ROOT_OPTIONS
Instance Attribute Summary
Attributes inherited from Pindo::Command
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ Forcepush
constructor
A new instance of Forcepush.
- #run ⇒ Object
- #validate! ⇒ Object
Methods inherited from Pindo::Command
Methods included from Funlog::Mixin
Methods included from Pindoconfig::Mixin
Methods included from Githelper
#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag
Methods included from Executable
capture_command, #executable, execute_command, which, which!
Constructor Details
#initialize(argv) ⇒ Forcepush
Returns a new instance of Forcepush.
26 27 28 29 30 31 32 |
# File 'lib/pindo/command/lib/forcepush.rb', line 26 def initialize(argv) @pod_spec_file = argv.shift_argument || nil @project_dir = argv.option('p') super(argv) @additional_args = argv.remainder! end |
Class Method Details
.options ⇒ Object
20 21 22 23 24 |
# File 'lib/pindo/command/lib/forcepush.rb', line 20 def self. [ ['--p', '指定需要lint的pod库所在目录, 例如 --p=~/Users/xxx/MyPod'], ].concat(super) end |
Instance Method Details
#run ⇒ Object
39 40 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 78 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 116 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 |
# File 'lib/pindo/command/lib/forcepush.rb', line 39 def run working_dir = @project_dir process_need_add_files(project_dir:working_dir) podspecs = [] if @pod_spec_file && (@pod_spec_file.to_s.end_with?('.podspec') || @pod_spec_file.to_s.end_with?('.json')) podspecs = [@pod_spec_file] else podspecs = Pathname.glob(File.join(working_dir, '*.podspec{.json,}')) end if podspecs.count.zero? raise Informative, '工作目录下没有任何podspec文件' end sources = Pod::Config.instance.sources_manager.all pod_array = pindo_single_config.pod_repo_dict pod_index_url = nil if !pod_array.nil? pod_index_url = pod_array['podindex'] else raise Informative, '私有Pod索引地址未知!!' end private_source = sources.select { |s| s.git? && s.url.to_s.eql?(pod_index_url)}.first if private_source.nil? raise Informative, "私有Pod索引地址未知!" end begin puts private_source_branch = "master" git!(%W(-C #{private_source.repo} reset --hard)) git!(%W(-C #{private_source.repo} clean -dfx)) git!(%W(-C #{private_source.repo} branch --set-upstream-to=origin/#{private_source_branch} #{private_source_branch})) git!(%W(-C #{private_source.repo} pull)) rescue StandardError => e raise Informative, "私有Pod索引目录异常,请删除#{private_source.repo}重新新下载" end pod_index_url_header = pod_index_url.slice(0, pod_index_url.rindex('/')) pod_index_url_git_org = File.basename(pod_index_url_header) working_dir_git_url = git!(%W(-C #{working_dir} config --get remote.origin.url)).chomp working_dir_git_url_header = working_dir_git_url.slice(0, working_dir_git_url.rindex('/')) working_dir_git_org = File.basename(working_dir_git_url_header) if working_dir_git_org.include?(":") working_dir_git_org = working_dir_git_org.slice(working_dir_git_org.rindex(':')+1, working_dir_git_org.size()) end puts "pod本地地址: #{working_dir}" puts "pod远程地址: #{working_dir_git_url}" puts "索引本地地址: #{private_source.repo}" puts "索引远程地址: #{private_source.url}" puts pod_index_url_git_org puts working_dir_git_org if pod_index_url_git_org != working_dir_git_org puts puts "索引库地址:#{pod_index_url_git_org}" puts "Pod库地址:#{working_dir_git_org}" answer = agree("私有Pod索引地址与工作目录不一致, 是否继续推送(Y/n):") unless answer raise Informative, "私有Pod索引地址与工作目录不一致!!!请使用pindo env 切换环境后再推送" end end puts puts "即将强制推送如下Pod库:" command_array = [] podspecs.each do |podspec| puts puts podspec podspec_obj = Pod::Specification.from_file(podspec) pod_name = podspec_obj.name tag_name = podspec_obj.version.to_s puts "名称: #{pod_name} 版本: #{tag_name}" end puts answer = agree("确定强制推送以上Pod库(Y/n):") unless answer raise Informative, "停止推送!!!" end puts "先检查对应的tag是否添加" podspecs.each do |podspec| puts puts podspec podspec_obj = Pod::Specification.from_file(podspec) pod_name = podspec_obj.name tag_name = podspec_obj.version.to_s add_tag_with_check(local_repo_dir:working_dir, tag_name:tag_name) end puts "强制推送中..." podspecs.each do |podspec| podspec_obj = Pod::Specification.from_file(podspec) pod_name = podspec_obj.name tag_name = podspec_obj.version.to_s dest_dir = File.join(private_source.repo,pod_name, tag_name) puts dest_dir begin FileUtils.mkdir_p(dest_dir) rescue StandardError => e end FileUtils.cp_r(podspec, File.join(dest_dir, File.basename(podspec))) puts "上传到仓库 #{private_source.repo}" git_addpush_repo(path:private_source.repo, message:"add #{pod_name} #{tag_name}") end end |
#validate! ⇒ Object
34 35 36 37 |
# File 'lib/pindo/command/lib/forcepush.rb', line 34 def validate! super @project_dir=Dir.pwd if @project_dir.nil? || @project_dir.empty? end |