Skip to content

Commit

Permalink
git apply works for misconfigured worktrees
Browse files Browse the repository at this point in the history
Fixes #69
  • Loading branch information
flavorjones committed Feb 13, 2017
1 parent f078a8a commit e84075b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mini_portile2/mini_portile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def apply_patch(patch_file)
message "Running git apply with #{file}... "
# By --work-tree=. git-apply uses the current directory as
# the project root and will not search upwards for .git.
execute('patch', ["git", "--work-tree=.", "apply", "--whitespace=warn", file], :initial_message => false)
execute('patch', ["git", "--git-dir=.", "--work-tree=.", "apply", "--whitespace=warn", file], :initial_message => false)
}
when which('patch')
lambda { |file|
Expand Down
45 changes: 45 additions & 0 deletions test/test_cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,48 @@ def test_install
assert_equal( ["install"].inspect, IO.read(txt).chomp )
end
end

class TestCookWithBrokenGitDir < TestCase
#
# this is a test for #69
# https://github.com/flavorjones/mini_portile/issues/69
#
attr_accessor :assets_path, :tar_path, :recipe

def before_all
super
@assets_path = File.expand_path("../assets", __FILE__)
@tar_path = File.expand_path("../../tmp/test-mini-portile-1.0.0.tar.gz", __FILE__)

@git_dir = File.join(@assets_path, "git-broken")
FileUtils.rm_rf @git_dir
FileUtils.mkdir_p @git_dir
Dir.chdir(@git_dir) do
File.open ".git", "w" do |f|
f.write "gitdir: /nonexistent"
end
end

create_tar(@tar_path, @assets_path, "test mini portile-1.0.0")

@recipe = MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
recipe.files << "file://#{@tar_path}"
recipe.patch_files << File.join(@assets_path, "patch 1.diff")
recipe.configure_options << "--option=\"path with 'space'\""
end

Dir.chdir(@git_dir) do
@recipe.cook
end
end

def after_all
FileUtils.rm_rf @git_dir
end

def test_patch
patch1 = File.join(work_dir, "patch 1.txt")
assert File.exist?(patch1), patch1
assert_match( /^\tchange 1/, IO.read(patch1) )
end
end

0 comments on commit e84075b

Please sign in to comment.