Class: Commands::FormatHelper
- Inherits:
-
Object
- Object
- Commands::FormatHelper
- Defined in:
- lib/commands/format_helper.rb
Instance Method Summary collapse
-
#options ⇒ Object
holds the options that were passed you can set any initial defaults here.
- #register(opts, global_options) ⇒ Object
-
#required_options ⇒ Object
required options.
- #run(global_options) ⇒ Object
Instance Method Details
#options ⇒ Object
holds the options that were passed you can set any initial defaults here
13 14 15 16 |
# File 'lib/commands/format_helper.rb', line 13 def @options ||= { } end |
#register(opts, global_options) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/commands/format_helper.rb', line 24 def register(opts, ) opts. = "Usage: format_helper [options]" opts.description = "Create checkouts and removes after format merge - only for android code reformat." opts.on('-n', "--dry-run", "Perform a dry run.") do |v| [:dry_run] = true end end |
#required_options ⇒ Object
required options
19 20 21 22 |
# File 'lib/commands/format_helper.rb', line 19 def @required_options ||= Set.new [ ] end |
#run(global_options) ⇒ Object
33 34 35 36 37 38 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 |
# File 'lib/commands/format_helper.rb', line 33 def run() if ARGV.length > 0 raise "You must specify all arguments with their options." end dry_run = !![:dry_run] # get config based on name of current dir info = EbmSharedLib.get_config_from_top_dir # Back up to version parent dir. This directory contains the top level repos. top_dir = Dir.pwd merge_failed = false repos = info[:repos] repos.each do |repo| repo_name = EbmSharedLib.get_repo_name(repo[:git_path]) repo_path = "#{top_dir}/#{repo_name}" branch = repo[:branch] base_branch = repo[:base_branch] puts("\n#{repo_name} format_helper:\n"); cmd = "git status --short" result = EbmSharedLib::CL.do_cmd_output(cmd, repo_path) if $?.exitstatus != 0 raise "Git status failed for #{repo_name}." end pairs = result.split len = pairs.length cur = 0 matches = 0 while true if cur == len break end code = pairs[cur] cur += 1 path = pairs[cur] cur += 1 if code == "UU" matches +=1 #puts "#{code} - #{path}" cmd = "git checkout --ours -- #{path}" if dry_run puts cmd else if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Git checkout failed for #{path}." end cmd = "git add #{path}" if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Git add failed for #{path}." end end elsif code == "DU" matches += 1 cmd = "git rm #{path}" if dry_run puts cmd else if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0 raise "Git rm failed for #{path}." end end end end end end |