Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions bin/GitUtility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,24 @@ 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)
return nil if path.nil? || !File.exist?(path)
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
Expand All @@ -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