|
1 | 1 | require 'rchardet'
|
2 | 2 | require 'tempfile'
|
| 3 | +require 'zlib' |
3 | 4 |
|
4 | 5 | module Git
|
5 | 6 |
|
@@ -705,10 +706,14 @@ def unmerged
|
705 | 706 |
|
706 | 707 | def conflicts # :yields: file, your, their
|
707 | 708 | self.unmerged.each do |f|
|
708 |
| - your = Tempfile.new("YOUR-#{File.basename(f)}").path |
| 709 | + your_tempfile = Tempfile.new("YOUR-#{File.basename(f)}") |
| 710 | + your = your_tempfile.path |
| 711 | + your_tempfile.close # free up file for git command process |
709 | 712 | command('show', ":2:#{f}", true, "> #{escape your}")
|
710 | 713 |
|
711 |
| - their = Tempfile.new("THEIR-#{File.basename(f)}").path |
| 714 | + their_tempfile = Tempfile.new("THEIR-#{File.basename(f)}") |
| 715 | + their = their_tempfile.path |
| 716 | + their_tempfile.close # free up file for git command process |
712 | 717 | command('show', ":3:#{f}", true, "> #{escape their}")
|
713 | 718 | yield(f, your, their)
|
714 | 719 | end
|
@@ -886,7 +891,13 @@ def archive(sha, file = nil, opts = {})
|
886 | 891 | arr_opts << "--remote=#{opts[:remote]}" if opts[:remote]
|
887 | 892 | arr_opts << sha
|
888 | 893 | arr_opts << '--' << opts[:path] if opts[:path]
|
889 |
| - command('archive', arr_opts, true, (opts[:add_gzip] ? '| gzip' : '') + " > #{escape file}") |
| 894 | + command('archive', arr_opts, true, " > #{escape file}") |
| 895 | + if opts[:add_gzip] |
| 896 | + file_content = File.read(file) |
| 897 | + Zlib::GzipWriter.open(file) do |gz| |
| 898 | + gz.write(file_content) |
| 899 | + end |
| 900 | + end |
890 | 901 | return file
|
891 | 902 | end
|
892 | 903 |
|
@@ -1077,14 +1088,22 @@ def run_command(git_cmd, &block)
|
1077 | 1088 | end
|
1078 | 1089 |
|
1079 | 1090 | def escape(s)
|
1080 |
| - # Check if on Windows via RUBY_PLATFORM (CRuby) and RUBY_DESCRIPTION (JRuby) |
1081 |
| - win_platform_regex = /mingw|mswin/ |
1082 |
| - return "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'" if RUBY_PLATFORM !~ win_platform_regex && RUBY_DESCRIPTION !~ win_platform_regex |
| 1091 | + windows_platform? ? escape_for_windows(s) : escape_for_sh(s) |
| 1092 | + end |
1083 | 1093 |
|
| 1094 | + def escape_for_sh(s) |
| 1095 | + "'#{s && s.to_s.gsub('\'','\'"\'"\'')}'" |
| 1096 | + end |
| 1097 | + |
| 1098 | + def escape_for_windows(s) |
| 1099 | + # Windows does not need single quote escaping inside double quotes |
| 1100 | + %Q{"#{s}"} |
| 1101 | + end |
1084 | 1102 |
|
1085 |
| - # Keeping the old escape format for windows users |
1086 |
| - escaped = s.to_s.gsub('\'', '\'\\\'\'') |
1087 |
| - return %Q{"#{escaped}"} |
| 1103 | + def windows_platform? |
| 1104 | + # Check if on Windows via RUBY_PLATFORM (CRuby) and RUBY_DESCRIPTION (JRuby) |
| 1105 | + win_platform_regex = /mingw|mswin/ |
| 1106 | + RUBY_PLATFORM =~ win_platform_regex || RUBY_DESCRIPTION =~ win_platform_regex |
1088 | 1107 | end
|
1089 | 1108 |
|
1090 | 1109 | end
|
|
0 commit comments