Created
June 16, 2009 01:47
-
-
Save mattn/130475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 70c770e81efd42323c9842e8ce8d4608a822d02a Mon Sep 17 00:00:00 2001 | |
From: mattn <[email protected]> | |
Date: Tue, 16 Jun 2009 10:48:05 +0900 | |
Subject: [PATCH] win32 support. | |
--- | |
lib/grit.rb | 4 +++- | |
lib/grit/git.rb | 16 ++++++++++++---- | |
2 files changed, 15 insertions(+), 5 deletions(-) | |
diff --git a/lib/grit.rb b/lib/grit.rb | |
index 407a935..5f5b5fd 100644 | |
--- a/lib/grit.rb | |
+++ b/lib/grit.rb | |
@@ -9,7 +9,9 @@ require 'timeout' | |
require 'logger' | |
require 'digest/sha1' | |
-if defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby' | |
+if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/ | |
+ require 'win32/open3' | |
+elsif defined? RUBY_ENGINE && RUBY_ENGINE == 'jruby' | |
require 'open3' | |
else | |
require 'open3_detach' | |
diff --git a/lib/grit/git.rb b/lib/grit/git.rb | |
index 128506d..0cd4fa4 100644 | |
--- a/lib/grit/git.rb | |
+++ b/lib/grit/git.rb | |
@@ -18,7 +18,11 @@ module Grit | |
attr_accessor :git_binary, :git_timeout, :git_max_size | |
end | |
- self.git_binary = "/usr/bin/env git" | |
+ if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/ | |
+ self.git_binary = "git" # using search path | |
+ else | |
+ self.git_binary = "/usr/bin/env git" | |
+ end | |
self.git_timeout = 10 | |
self.git_max_size = 5242880 # 5.megabytes | |
@@ -60,9 +64,13 @@ module Grit | |
timeout = true if timeout.nil? | |
opt_args = transform_options(options) | |
- ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|') ? a : "'#{e(a)}'" } | |
- | |
- call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" | |
+ if RUBY_PLATFORM.downcase =~ /mswin(?!ce)|mingw|bccwin/ | |
+ ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|') ? a : "\"#{e(a)}\"" } | |
+ call = "#{prefix}#{Git.git_binary} --git-dir=\"#{self.git_dir}\" #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" | |
+ else | |
+ ext_args = args.reject { |a| a.empty? }.map { |a| (a == '--' || a[0].chr == '|') ? a : "'#{e(a)}'" } | |
+ call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{e(postfix)}" | |
+ end | |
Grit.log(call) if Grit.debug | |
response, err = timeout ? sh(call) : wild_sh(call) | |
Grit.log(response) if Grit.debug | |
-- | |
1.6.3.msysgit.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment