diff --git a/bin/GitUtility.rb b/bin/GitUtility.rb index 35576a8..86d4fe5 100644 --- a/bin/GitUtility.rb +++ b/bin/GitUtility.rb @@ -31,6 +31,16 @@ def self.get_git_has_uncommitted_changes(path) return run_git(path, 'status --porcelain') != nil end + # Git executable for shell invocation: PATH name or quoted path when $git_bin_path is set. + def self.git_exe + return $git_bin_path.to_s.empty? ? 'git' : "\"#{$git_bin_path}git\"" + end + + # Shell stderr redirect for discarding git noise: cmd.exe has no /dev/null (use 2>nul); Unix uses 2>/dev/null. + def self.git_stderr_null + return (RUBY_PLATFORM =~ /mswin|mingw|cygwin/) ? '2>nul' : '2>/dev/null' + end + # Runs a git command from the directory of path. # Returns trimmed output as string, or nil on empty output / error. def self.run_git(path, args) @@ -38,7 +48,7 @@ def self.run_git(path, args) dir = File.directory?(path) ? path : File.dirname(path) curr_dir = Dir.pwd Dir.chdir(dir) - cmd = ($git_bin_path.to_s.empty? ? 'git' : "\"#{$git_bin_path}git\"") + ' ' + args + ' 2>/dev/null' + cmd = "#{git_exe} #{args} #{git_stderr_null}" socket = IO.popen(cmd) begin out = socket.gets(nil).to_s.strip @@ -52,5 +62,5 @@ def self.run_git(path, args) return nil end - private_class_method :run_git + private_class_method :git_exe, :git_stderr_null, :run_git end