Skip to content

Commit

Permalink
sets --work-tree so that adds work
Browse files Browse the repository at this point in the history
  • Loading branch information
davetron5000 committed Jun 20, 2009
1 parent 4ac4aca commit 8c4ec13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions lib/grit/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def self.with_timeout(timeout = 10.seconds)
Grit::Git.git_timeout = old_timeout
end

attr_accessor :git_dir, :bytes_read
attr_accessor :git_dir, :bytes_read, :work_tree

def initialize(git_dir)
self.git_dir = git_dir
self.work_tree = git_dir =~ /\.git$/ ? git_dir.gsub(/\/git$/,'') : git_dir
self.bytes_read = 0
end

Expand Down Expand Up @@ -62,7 +63,7 @@ def run(prefix, cmd, postfix, options, args)
opt_args = transform_options(options)
ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|') ? a : "'#{e(a)}'" }

call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
call = "#{prefix}#{Git.git_binary} --work-tree='#{self.work_tree}' --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}"
Grit.log(call) if Grit.debug
response, err = timeout ? sh(call) : wild_sh(call)
Grit.log(response) if Grit.debug
Expand Down
10 changes: 5 additions & 5 deletions test/test_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ def test_raises_on_slow_shell
end

def test_it_really_shell_escapes_arguments_to_the_git_shell
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo --bar='bazz\\'er'")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo --bar='bazz\\'er'")
@git.foo(:bar => "bazz'er")
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' bar -x 'quu\\'x'")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' bar -x 'quu\\'x'")
@git.bar(:x => "quu'x")
end

def test_it_shell_escapes_the_standalone_argument
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar\\'s'")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo 'bar\\'s'")
@git.foo({}, "bar's")

@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' foo 'bar' '\\; echo \\'noooo\\''")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' foo 'bar' '\\; echo \\'noooo\\''")
@git.foo({}, "bar", "; echo 'noooo'")
end

def test_piping_should_work_on_1_9
@git.expects(:sh).with("#{Git.git_binary} --git-dir='#{@git.git_dir}' archive 'master' | gzip")
@git.expects(:sh).with("#{Git.git_binary} --work-tree='#{@git.work_tree}' --git-dir='#{@git.git_dir}' archive 'master' | gzip")
@git.archive({}, "master", "| gzip")
end
end

0 comments on commit 8c4ec13

Please sign in to comment.