Skip to content

Commit

Permalink
make release_to_github work when gem directory is not at top level
Browse files Browse the repository at this point in the history
  • Loading branch information
devrandom authored and technicalpickles committed Jan 6, 2010
1 parent 93f5b0d commit 3950444
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/jeweler/commands/release_to_github.rb
@@ -1,3 +1,5 @@
require 'pathname'

class Jeweler
module Commands
class ReleaseToGithub
Expand Down Expand Up @@ -29,8 +31,9 @@ def clean_staging_area?
end

def commit_gemspec!
repo.add(gemspec_helper.path)
output.puts "Committing #{gemspec_helper.path}"
gemspec_gitpath = working_subdir.join(gemspec_helper.path)
repo.add(gemspec_gitpath.to_s)
output.puts "Committing #{gemspec_gitpath}"
repo.commit "Regenerated gemspec for version #{version}"
end

Expand All @@ -41,14 +44,25 @@ def regenerate_gemspec!

def gemspec_changed?
`git status` # OMGHAX. status always ends up being 'M' unless this runs
status = repo.status[gemspec_helper.path]
status = repo.status[working_subdir.join(gemspec_helper.path).to_s]
! status.type.nil?
end

def gemspec_helper
@gemspec_helper ||= Jeweler::GemSpecHelper.new(self.gemspec, self.base_dir)
end

def working_subdir
return @working_subdir if @working_subdir
cwd = base_dir_path
@working_subdir = cwd.relative_path_from(Pathname.new(repo.dir.path))
@working_subdir
end

def base_dir_path
Pathname.new(base_dir).realpath
end

def self.build_for(jeweler)
command = self.new

Expand Down
76 changes: 76 additions & 0 deletions test/jeweler/commands/test_release_to_github.rb
@@ -1,4 +1,5 @@
require 'test_helper'
require 'pathname'

class Jeweler
module Commands
Expand Down Expand Up @@ -247,6 +248,7 @@ class TestReleaseToGithub < Test::Unit::TestCase
:gemspec_helper => @gemspec_helper,
:version => '1.2.3'

stub(@command).working_subdir { Pathname.new(".") }
@command.commit_gemspec!
end

Expand All @@ -260,6 +262,80 @@ class TestReleaseToGithub < Test::Unit::TestCase

end

context "commit_gemspec! in top dir" do
setup do
@repo = Object.new

stub(@repo) do
add(anything)
commit(anything)
end

@gemspec_helper = Object.new
stub(@gemspec_helper) do
path {'zomg.gemspec'}
update_version('1.2.3')
end

@output = StringIO.new

@command = Jeweler::Commands::ReleaseToGithub.new :output => @output,
:repo => @repo,
:gemspec_helper => @gemspec_helper,
:version => '1.2.3',
:base_dir => '.'

@dir = Object.new
stub(@repo).dir { @dir }
stub(@dir).path { "/x/y/z" }

stub(@command).base_dir_path { Pathname.new("/x/y/z") }

@command.commit_gemspec!
end

should "add gemspec to repository" do
assert_received(@repo) {|repo| repo.add('zomg.gemspec') }
end
end

context "commit_gemspec! in sub dir" do
setup do
@repo = Object.new

stub(@repo) do
add(anything)
commit(anything)
end

@gemspec_helper = Object.new
stub(@gemspec_helper) do
path {'zomg.gemspec'}
update_version('1.2.3')
end

@output = StringIO.new

@command = Jeweler::Commands::ReleaseToGithub.new :output => @output,
:repo => @repo,
:gemspec_helper => @gemspec_helper,
:version => '1.2.3',
:base_dir => '.'

@dir = Object.new
stub(@repo).dir { @dir }
stub(@dir).path { "/x/y/z" }

stub(@command).base_dir_path { Pathname.new("/x/y/z/gem") }

@command.commit_gemspec!
end

should "add gemspec to repository" do
assert_received(@repo) {|repo| repo.add('gem/zomg.gemspec') }
end
end

context "release_tagged? when no tag exists" do
setup do
@repo = Object.new
Expand Down

0 comments on commit 3950444

Please sign in to comment.