Sha256: b4f2961e196240f3423bb2a12384ef6f7f6c3f8daaec93f8185191fd19f13ddf

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

require 'uri'

require 'gerrit/cli/command/base'
require 'gerrit/cli/constants'
require 'gerrit/cli/errors'

# Posts reviews to Gerrit. Assumes that your repo has at least one Gerrit
# remote.
class Gerrit::Cli::Command::Push < Gerrit::Cli::Command::Base
  def initialize(logger, runner)
    super(logger)

    @branch = "master"
    @runner = runner
  end

  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

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

  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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gerrit-cli-0.0.1 lib/gerrit/cli/command/push.rb