Class: Gerrit::Cli::Command::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/gerrit/cli/command/push.rb

Overview

Posts reviews to Gerrit. Assumes that your repo has at least one Gerrit remote.

Instance Attribute Summary

Attributes inherited from Base

#option_parser

Instance Method Summary collapse

Methods inherited from Base

#name, #show_usage, #summary

Constructor Details

#initialize(logger, runner) ⇒ Push

Returns a new instance of Push.



10
11
12
13
14
15
# File 'lib/gerrit/cli/command/push.rb', line 10

def initialize(logger, runner)
  super(logger)

  @branch = "master"
  @runner = runner
end

Instance Method Details

#get_current_branchObject



55
56
57
58
59
# File 'lib/gerrit/cli/command/push.rb', line 55

def get_current_branch
  @logger.debug("Getting current branch")
  output = @runner.capture!("git symbolic-ref HEAD")
  output.gsub(/^refs\/heads\//,"")
end

#run(argv) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gerrit/cli/command/push.rb', line 34

def run(argv)
  args = @option_parser.parse(argv)

  remote = nil
  case args.length
  when 1
    remote = args[0]
  when 0
    remote = "origin"
  else
    raise Gerrit::Cli::UsageError.new("Incorrect number of arguments")
  end

  topic = get_current_branch()

  cmd = ["git push",
         remote,
         "HEAD:refs/for/#{@branch}/#{topic}"].join(" ")
  @runner.system!(cmd)
end

#setup_option_parserObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gerrit/cli/command/push.rb', line 17

def setup_option_parser
  super

  @option_parser.banner =
    "Post changes from the current branch to Gerrit for review."

  @option_parser.on('-b', '--branch BRANCH',
                    "The remote branch these changes should be merged into." \
                    + "Master is assumed by default.") do |branch|
    @branch = branch
  end
end

#usageObject



30
31
32
# File 'lib/gerrit/cli/command/push.rb', line 30

def usage
  "Usage: gerrit push [options] [<remote>]\n\n" + @option_parser.help
end