Skip to content

Commit

Permalink
Merge commit 'a88d1d96985074db9c37f3f50a45fd089d8b4a12' into smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Jul 23, 2009
2 parents 4e694b9 + a88d1d9 commit 0bbd902
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 @@ -42,10 +42,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.gsub(/\/\.git$/,'')
self.bytes_read = 0
end

Expand Down Expand Up @@ -223,7 +224,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 @@ -64,22 +64,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

Expand Down

0 comments on commit 0bbd902

Please sign in to comment.