Class: Commands::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/commands/commit.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/commit.rb', line 13

def options
  @options ||= {
  }
end

#register(opts, global_options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/commands/commit.rb', line 25

def register(opts, global_options)
  opts.banner = "Usage: commit [options]"
  opts.description = "Commit changes to local repos."

  opts.on('-c', "--comment comment", "Required - The comment you want to use for the commit - alternate use -m.") do |v|
    options[:comment] = v
  end

  opts.on('-m', "--comment comment", "Required - The comment you want to use for the commit - alternate use -c.") do |v|
    options[:comment] = v
  end

  opts.on('-a', "--add", "Also add all new files.") do |v|
    options[:add] = true
  end

  opts.on('-n', "--dry-run", "Perform a dry run.") do |v|
    options[:dry_run] = v
  end
end

#required_optionsObject

required options



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

def required_options
  @required_options ||= Set.new [
      :comment
  ]
end

#run(global_options) ⇒ Object



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
# File 'lib/commands/commit.rb', line 46

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
  comment = options[:comment]
  add = !!options[:add]
  dry_run = !!options[:dry_run] ? "--dry-run" : ""

  if ARGV.length > 0
    raise "You must specify all arguments with their options."
  end

  # 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

  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}"
      branch = repo[:branch]
      puts("\n#{repo_name} commit:\n");

      if (add)
        # first add any new files
        cmd = "git add #{dry_run} ."
        if EbmSharedLib::CL.do_cmd_result(cmd, repo_path) != 0
          raise "Git add all failed for #{repo_name}."
        end
      end

      cmd = "git commit #{dry_run} -am \"#{comment}\""
      exit_code = EbmSharedLib::CL.do_cmd_ignore_str(cmd, "nothing to commit", repo_path)
      if exit_code != 0 && exit_code != 999
          raise "Git commit failed for #{repo_name}."
      end
    end
  end

end