Skip to content

Commit

Permalink
specific git remote with default to origin
Browse files Browse the repository at this point in the history
  • Loading branch information
lanej committed Jan 20, 2015
1 parent b736eea commit 5574b75
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 32 deletions.
39 changes: 21 additions & 18 deletions lib/rubygems/commands/bump_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,30 @@ class Gem::Commands::BumpCommand < Gem::Command
attr_reader :arguments, :usage, :name

DEFAULTS = {
:version => '',
:commit => true,
:push => false,
:tag => false,
:release => false,
:key => '',
:host => '',
:quiet => false
:version => '',
:commit => true,
:push => false,
:tag => false,
:release => false,
:key => '',
:host => '',
:quiet => false,
:destination => "origin",
}

def initialize(options = {})
@name = 'bump'
super @name, 'Bump the gem version', default_options_with(options)

option :version, '-v', 'Target version: next [major|minor|patch|pre|release] or a given version number [x.x.x]'
option :commit, '-c', 'Perform a commit after incrementing gem version'
option :push, '-p', 'Push to the origin git repository'
option :tag, '-t', 'Create a git tag and push --tags to origin'
option :release, '-r', 'Build gem from a gemspec and push to rubygems.org'
option :key, '-k', 'When releasing: use the given API key from ~/.gem/credentials'
option :host, '-h', 'When releasing: push to a gemcutter-compatible host other than rubygems.org'
option :quiet, '-q', 'Do not output status messages'
option :version, '-v', 'Target version: next [major|minor|patch|pre|release] or a given version number [x.x.x]'
option :commit, '-c', 'Perform a commit after incrementing gem version'
option :push, '-p', 'Push to the git destination'
option :destination, '-d', 'destination git repository'
option :tag, '-t', 'Create a git tag and push --tags to git destination'
option :release, '-r', 'Build gem from a gemspec and push to rubygems.org'
option :key, '-k', 'When releasing: use the given API key from ~/.gem/credentials'
option :host, '-h', 'When releasing: push to a gemcutter-compatible host other than rubygems.org'
option :quiet, '-q', 'Do not output status messages'
end

def execute
Expand Down Expand Up @@ -83,8 +85,9 @@ def commit
end

def push
say "Pushing to the origin git repository" unless quiet?
system('git push origin')
destination = options[:destination]
say "Pushing to the #{destination} git repository" unless quiet?
system("git push #{destination}")
end

def release
Expand Down
18 changes: 10 additions & 8 deletions lib/rubygems/commands/release_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ class Gem::Commands::ReleaseCommand < Gem::Command
include Helpers, CommandOptions

DEFAULTS = {
:tag => false,
:quiet => false,
:key => '',
:host => ''
:tag => false,
:quiet => false,
:key => '',
:host => '',
:destination => "origin",
}

attr_reader :arguments, :usage, :name
Expand All @@ -19,10 +20,11 @@ def initialize(options = {})
@name = 'release'
super @name, 'Build gem from a gemspec and push to rubygems.org', default_options_with(options)

option :tag, '-t', 'Create a git tag and push --tags to origin'
option :quiet, '-q', 'Do not output status messages'
option :key, '-k', 'Use the given API key from ~/.gem/credentials'
option :host, '-h', 'Push to a gemcutter-compatible host other than rubygems.org'
option :tag, '-t', 'Create a git tag and push --tags to destination'
option :destination, '-d', 'Destination git repository'
option :quiet, '-q', 'Do not output status messages'
option :key, '-k', 'Use the given API key from ~/.gem/credentials'
option :host, '-h', 'Push to a gemcutter-compatible host other than rubygems.org'

@arguments = "gemspec - optional gemspec file name, will use the first *.gemspec if not specified"
@usage = "#{program_name} [gemspec]"
Expand Down
14 changes: 8 additions & 6 deletions lib/rubygems/commands/tag_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ class Gem::Commands::TagCommand < Gem::Command
include Helpers, CommandOptions

DEFAULTS = {
:quiet => false
:quiet => false,
:destination => "origin"
}

attr_reader :arguments, :usage, :name

def initialize(options = {})
@name = 'tag'
super @name, 'Create a git tag and push --tags to origin', default_options_with(options)
super @name, 'Create a git tag and push --tags to destination', default_options_with(options)

option :quiet, '-q', 'Do not output status messages'
option :quiet, '-q', 'Do not output status messages'
option :destination, '-d', 'Git destination'
end

def execute
Expand All @@ -33,11 +35,11 @@ def tag
def push
unless options[:push_tags_only]
say "Pushing to the origin git repository" unless quiet?
return false unless system('git push origin')
return false unless system("git push #{options[:destination]}")
end

say "Pushing --tags to the origin git repository" unless quiet?
system('git push --tags origin')
say "Pushing --tags to the #{options[:destination]} git repository" unless quiet?
system("git push --tags #{options[:destination]}")
end

def tag_name
Expand Down
29 changes: 29 additions & 0 deletions test/bump_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ def version(options = {})
command.invoke('--push')
end

test "gem bump --push -d fork" do
command = BumpCommand.new
in_gemspec_dirs do
command.expects(:system).with("git add #{version.send(:filename)}").returns(true)
end
command.expects(:system).with('git commit -m "Bump to 0.0.2"').returns(true)
command.expects(:system).with('git push fork').returns(true)
command.invoke('--push', '-d', 'fork')
end

test "gem bump --tag" do
command = BumpCommand.new
in_gemspec_dirs do
Expand Down Expand Up @@ -246,6 +256,25 @@ def version(options = {})
command.invoke('--tag', '--release')
end

test "gem bump --tag --release --destination fork" do
command = BumpCommand.new
in_gemspec_dirs do
command.expects(:system).with("git add #{version.send(:filename)}").returns(true)
end
command.expects(:system).with('git commit -m "Bump to 0.0.2"').returns(true)
command.expects(:system).with('git push fork').returns(true)

count = gemspec_dirs.size
ReleaseCommand.any_instance.expects(:build).times(count).returns(true)
ReleaseCommand.any_instance.expects(:push).times(count).returns(true)
ReleaseCommand.any_instance.expects(:cleanup).times(count).returns(true)

TagCommand.any_instance.expects(:tag).returns(true)
TagCommand.any_instance.expects(:push).returns(true)

command.invoke('--tag', '--release', '--destination', 'fork')
end

test "gem bump --release --key" do
command = BumpCommand.new
in_gemspec_dirs do
Expand Down
10 changes: 10 additions & 0 deletions test/tag_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ def setup
command.expects(:system).with("git push --tags origin").returns(:true)
command.execute
end

test "tag_command pushes to a specific git remote" do
command = TagCommand.new
command.options[:push_tags_only] = true
command.options[:destination] = "fork"
command.stubs(:gem_version).returns('1.0.0')
command.expects(:system).with("git tag -am \"tag v1.0.0\" v1.0.0").returns(:true)
command.expects(:system).with("git push --tags fork").returns(:true)
command.execute
end
end

0 comments on commit 5574b75

Please sign in to comment.