Subject: Use “--no-color” on certain Git commands
From: Michael Schutte <michi@debian.org>
Bug-Debian: http://bugs.debian.org/592673
“color.* = always” settings in the users’ Git configuration messes up
ruby-git’s parsing of the output of commands like “git branch” and “git
diff”. Avoid the problem by overriding this behaviour through the
“--no-color” switch.
Index: devel/lib/git/lib.rb
===================================================================
--- devel.orig/lib/git/lib.rb 2011-06-11 22:38:24.000000000 +0200
+++ devel/lib/git/lib.rb 2011-06-11 22:42:47.000000000 +0200
@@ -64,7 +64,7 @@
def log_commits(opts = {})
- arr_opts = ['--pretty=oneline']
+ arr_opts = ['--pretty=oneline', '--no-color']
arr_opts << "-#{opts[:count]}" if opts[:count]
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
arr_opts << "--until=#{opts[:until]}" if opts[:until].is_a? String
@@ -78,7 +78,7 @@
end
def full_log_commits(opts = {})
- arr_opts = ['--pretty=raw']
+ arr_opts = ['--pretty=raw', '--no-color']
arr_opts << "-#{opts[:count]}" if opts[:count]
arr_opts << "--skip=#{opts[:skip]}" if opts[:skip]
arr_opts << "--since=#{opts[:since]}" if opts[:since].is_a? String
@@ -197,7 +197,7 @@
def branches_all
arr = []
- command_lines('branch', '-a').each do |b|
+ command_lines('branch', ['--no-color', '-a']).each do |b|
current = (b[0, 2] == '* ')
arr << [b.gsub('* ', '').strip, current]
end
@@ -222,7 +222,7 @@
def grep(string, opts = {})
opts[:object] ||= 'HEAD'
- grep_opts = ['-n']
+ grep_opts = ['--no-color', '-n']
grep_opts << '-i' if opts[:ignore_case]
grep_opts << '-v' if opts[:invert_match]
grep_opts << '-e'
@@ -241,7 +241,7 @@
end
def diff_full(obj1 = 'HEAD', obj2 = nil, opts = {})
- diff_opts = ['-p']
+ diff_opts = ['--no-color', '-p']
diff_opts << obj1
diff_opts << obj2 if obj2.is_a?(String)
diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
@@ -250,7 +250,7 @@
end
def diff_stats(obj1 = 'HEAD', obj2 = nil, opts = {})
- diff_opts = ['--numstat']
+ diff_opts = ['--no-color', '--numstat']
diff_opts << obj1
diff_opts << obj2 if obj2.is_a?(String)
diff_opts << '--' << opts[:path_limiter] if opts[:path_limiter].is_a? String
@@ -272,7 +272,7 @@
# compares the index and the working directory
def diff_files
hsh = {}
- command_lines('diff-files').each do |line|
+ command_lines('diff-files', '--no-color').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,
@@ -284,7 +284,7 @@
# compares the index and the repository
def diff_index(treeish)
hsh = {}
- command_lines('diff-index', treeish).each do |line|
+ command_lines('diff-index', ['--no-color', treeish]).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,
@@ -508,7 +508,7 @@
def unmerged
unmerged = []
- command_lines('diff', ["--cached"]).each do |line|
+ command_lines('diff', ['--no-color', "--cached"]).each do |line|
unmerged << $1 if line =~ /^\* Unmerged path (.*)/
end
unmerged