From e7aa88747cd28e737c0318cccfa0afccf1cf659d Mon Sep 17 00:00:00 2001 From: Ofir Petrushka Date: Mon, 7 Sep 2020 16:41:07 +1000 Subject: [PATCH] Simplify git commands Signed-off-by: Ofir Petrushka --- lib/git/lib.rb | 3 +-- tests/units/test_logger.rb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 830c4dfe..8e6f8863 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -993,8 +993,7 @@ def with_custom_env_variables(&block) def command(cmd, opts = [], chdir = true, redirect = '', &block) global_opts = [] - global_opts << "--git-dir=#{@git_dir}" if !@git_dir.nil? - global_opts << "--work-tree=#{@git_work_dir}" if !@git_work_dir.nil? + global_opts << ["-C", "#{@git_work_dir}"] if !@git_work_dir.nil? global_opts << ["-c", "color.ui=false"] opts = [opts].flatten.map {|s| escape(s) }.join(' ') diff --git a/tests/units/test_logger.rb b/tests/units/test_logger.rb index b57ed102..4aa6ef75 100644 --- a/tests/units/test_logger.rb +++ b/tests/units/test_logger.rb @@ -19,7 +19,7 @@ def test_logger @git.branches.size logc = File.read(log.path) - assert(/INFO -- : git '--git-dir=[^']+' '--work-tree=[^']+' '-c' 'color.ui=false' branch '-a'/.match(logc)) + assert(/INFO -- : git '-C' '[^']+' '-c' 'color.ui=false' branch '-a'/.match(logc)) assert(/DEBUG -- : diff_over_patches/.match(logc)) log = Tempfile.new('logfile') @@ -31,7 +31,7 @@ def test_logger @git.branches.size logc = File.read(log.path) - assert(/INFO -- : git '--git-dir=[^']+' '--work-tree=[^']+' '-c' 'color.ui=false' branch '-a'/.match(logc)) + assert(/INFO -- : git '-C' '[^']+' '-c' 'color.ui=false' branch '-a'/.match(logc)) assert(!/DEBUG -- : diff_over_patches/.match(logc)) end