Skip to content
Snippets Groups Projects
Commit ade9c275 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'work_tree' into 'master'

Use git --work-tree when there is a working directory

See merge request !5
parents 30bebc10 e44758c2
No related branches found
No related tags found
No related merge requests found
== 2.7.0
* Remove the `chdir:` option for thread-safety
* Automatically set the `--work-tree=` Git option
== 2.6.9
* Fix commit diff issue. It shows empty diff for commit when files have changed mode
 
Loading
Loading
Loading
Loading
@@ -21,6 +21,8 @@ We patched existing grit library to use it inside GitLab
* Fixes symlinks omission from diff
* Added Gemfile
* Ruby 2.0 support
* Automatically set the `--work-tree=` option for Git
* Remove `chdir:` option from Grit::Git#native
* and much more small fixes
 
 
Loading
Loading
Loading
Loading
@@ -93,9 +93,9 @@ module Grit
 
attr_accessor :git_dir, :bytes_read, :work_tree
 
def initialize(git_dir)
def initialize(git_dir, options={})
self.git_dir = git_dir
self.work_tree = git_dir.gsub(/\/\.git$/,'')
self.work_tree = options[:work_tree]
self.bytes_read = 0
end
 
Loading
Loading
@@ -320,12 +320,12 @@ module Grit
input = options.delete(:input)
timeout = options.delete(:timeout); timeout = true if timeout.nil?
base = options.delete(:base); base = true if base.nil?
chdir = options.delete(:chdir)
 
# build up the git process argv
argv = []
argv << Git.git_binary
argv << "--git-dir=#{git_dir}" if base
argv << "--work-tree=#{work_tree}" if work_tree
argv << cmd.to_s.tr('_', '-')
argv.concat(options_to_argv(options))
argv.concat(args)
Loading
Loading
@@ -336,7 +336,6 @@ module Grit
process =
Child.new(env, *(argv + [{
:input => input,
:chdir => chdir,
:timeout => (Grit::Git.git_timeout if timeout == true),
:max => (Grit::Git.git_max_size if timeout == true)
}]))
Loading
Loading
Loading
Loading
@@ -54,7 +54,7 @@ module Grit
raise NoSuchPathError.new(epath)
end
 
self.git = Git.new(self.path)
self.git = Git.new(self.path, work_tree: self.working_dir)
end
 
# Public: Initialize a git repository (create it on the filesystem). By
Loading
Loading
Loading
Loading
@@ -116,7 +116,7 @@ module Grit
# compares the index and the working directory
def diff_files
hsh = {}
@base.git.diff_files(chdir: @base.working_dir).split("\n").each do |line|
@base.git.diff_files({}).split("\n").each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
hsh[file] = {:path => file, :mode_file => mode_src.to_s[1, 7], :mode_index => mode_dest,
Loading
Loading
@@ -128,7 +128,7 @@ module Grit
# compares the index and the repository
def diff_index(treeish)
hsh = {}
@base.git.diff_index({chdir: @base.working_dir}, treeish).split("\n").each do |line|
@base.git.diff_index({}, treeish).split("\n").each do |line|
(info, file) = line.split("\t")
(mode_src, mode_dest, sha_src, sha_dest, type) = info.split
hsh[file] = {:path => file, :mode_repo => mode_src.to_s[1, 7], :mode_index => mode_dest,
Loading
Loading
@@ -139,7 +139,7 @@ module Grit
 
def ls_files
hsh = {}
lines = @base.git.ls_files({chdir: @base.working_dir, :stage => true})
lines = @base.git.ls_files({:stage => true})
lines.split("\n").each do |line|
(info, file) = line.split("\t")
(mode, sha, stage) = info.split
Loading
Loading
Loading
Loading
@@ -88,7 +88,7 @@ class TestGit < Test::Unit::TestCase
args = [
{ 'A' => 'B' },
Grit::Git.git_binary, "--git-dir=#{@git.git_dir}", "help", "-a",
{:input => nil, :chdir => nil, :timeout => Grit::Git.git_timeout, :max => Grit::Git.git_max_size}
{:input => nil, :timeout => Grit::Git.git_timeout, :max => Grit::Git.git_max_size}
]
p = Grit::Git::Child.new(*args)
Grit::Git::Child.expects(:new).with(*args).returns(p)
Loading
Loading
Loading
Loading
@@ -26,9 +26,9 @@ class TestIndexStatus < Test::Unit::TestCase
end
 
def test_status
Git.any_instance.expects(:diff_index).with({chdir: GRIT_REPO}, 'HEAD').returns(fixture('diff_index'))
Git.any_instance.expects(:diff_files).with({chdir: GRIT_REPO}).returns(fixture('diff_files'))
Git.any_instance.expects(:ls_files).with({chdir: GRIT_REPO, stage: true}).returns(fixture('ls_files'))
Git.any_instance.expects(:diff_index).with({}, 'HEAD').returns(fixture('diff_index'))
Git.any_instance.expects(:diff_files).with({}).returns(fixture('diff_files'))
Git.any_instance.expects(:ls_files).with({stage: true}).returns(fixture('ls_files'))
status = @r.status
stat = status['lib/grit/repo.rb']
assert_equal stat.sha_repo, "71e930d551c413a123f43e35c632ea6ba3e3705e"
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment