Class: Commands::RemoveMergedBranches

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/remove_merged_branches.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject

holds the options that were passed you can set any initial defaults here



13
14
15
16
# File 'lib/commands/remove_merged_branches.rb', line 13

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/commands/remove_merged_branches.rb', line 24

def register(opts, global_options)
  opts.banner = "Usage: status"
  opts.description = "Shows the git status of all repos in the config."
  opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
    options[:dry_run] = true
  end

end

#required_optionsObject

required options



19
20
21
22
# File 'lib/commands/remove_merged_branches.rb', line 19

def required_options
  @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
# File 'lib/commands/remove_merged_branches.rb', line 33

def run(global_options)

  # see if we can open the config file - we append the .config suffix
  # the file is expected to be in JSON format

  # determine config_name by extracting parent of our directory
  info = EbmSharedLib.get_config_from_top_dir
  dry_run = !!options[:dry_run] ? "--dry-run" : ""

  # Back up to version parent dir.  This directory contains the top level repos.
#      top_dir = File.expand_path("#{Dir.pwd}/..")
  top_dir = Dir.pwd

  repos = info[:repos]
  repos.each do |repo|
    if repo[:create_dev_branch]
      repo_name = EbmSharedLib.get_repo_name(repo[:git_path])
      repo_path = "#{top_dir}/#{repo_name}"
      File.open("#{repo_name}/merged_branches.txt").each do |line|
    	  cmd = "git push #{dry_run} origin :#{line}"
        if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
        end
      end
    end
  end
end