Permalink
Browse files

make release_to_github work when gem directory is not at top level

  • Loading branch information...
1 parent 93f5b0d commit 39504442d32df1946e8b4c8140996fa6445d0b50 @devrandom devrandom committed with technicalpickles Dec 6, 2009
Showing with 93 additions and 3 deletions.
  1. +17 −3 lib/jeweler/commands/release_to_github.rb
  2. +76 −0 test/jeweler/commands/test_release_to_github.rb
@@ -1,3 +1,5 @@
+require 'pathname'
+
class Jeweler
module Commands
class ReleaseToGithub
@@ -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
@@ -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
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'pathname'
class Jeweler
module Commands
@@ -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
@@ -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

0 comments on commit 3950444

Please sign in to comment.