Permalink
Browse files

Merge branch 'master' of git://github.com/relevance/grit

Conflicts:

	grit.gemspec
  • Loading branch information...
2 parents 403c983 + d40e1f0 commit 25812380387fdd55f916652be4881c6f11600d6f @cho45 committed Jun 28, 2008
Showing with 49 additions and 6 deletions.
  1. +3 −0 Manifest.txt
  2. +9 −1 lib/grit.rb
  3. +2 −2 lib/grit/git.rb
  4. +3 −3 test/test_commit.rb
  5. +32 −0 test/test_grit.rb
View
@@ -11,6 +11,7 @@ lib/grit/config.rb
lib/grit/diff.rb
lib/grit/errors.rb
lib/grit/git.rb
+lib/grit/index.rb
lib/grit/lazy.rb
lib/grit/ref.rb
lib/grit/repo.rb
@@ -46,8 +47,10 @@ test/test_commit.rb
test/test_config.rb
test/test_diff.rb
test/test_git.rb
+test/test_grit.rb
test/test_head.rb
test/test_reality.rb
+test/test_remote.rb
test/test_repo.rb
test/test_tag.rb
test/test_tree.rb
View
@@ -6,6 +6,7 @@
# stdlib
require 'timeout'
+require 'logger'
# third party
require 'rubygems'
@@ -28,11 +29,18 @@
require 'grit/remote'
module Grit
+
class << self
+ # Set +debug+ to true to log all git calls and responses
attr_accessor :debug
+ # The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
+ attr_accessor :logger
+ def log(str)
+ logger.debug { str }
+ end
end
-
self.debug = false
+ @logger ||= ::Logger.new(STDOUT)
VERSION = '0.8.1'
end
View
@@ -55,9 +55,9 @@ def run(prefix, cmd, postfix, options, args)
ext_args = args.map { |a| a == '--' ? a : "'#{a}'" }
call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{postfix}"
- puts call if Grit.debug
+ Grit.log(call) if Grit.debug
response = timeout ? sh(call) : wild_sh(call)
- puts response if Grit.debug
+ Grit.log(response) if Grit.debug
response
end
View
@@ -165,12 +165,12 @@ def test_inspect
def test_to_hash
@c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
-
+ date = Time.parse('Wed Oct 10 03:06:12 -0400 2007')
expected = {
'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
- 'committed_date' => "2007-10-10T00:06:12-07:00",
+ 'committed_date' => date.xmlschema,
'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
- 'authored_date' => "2007-10-10T00:06:12-07:00",
+ 'authored_date' => date.xmlschema,
'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
'message' => "implement Grit#heads",
'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
View
@@ -0,0 +1,32 @@
+require File.dirname(__FILE__) + '/helper'
+
+class TestGrit < Test::Unit::TestCase
+ def setup
+ @old_debug = Grit.debug
+ @old_logger = Grit.logger
+ Grit.debug = true
+ end
+
+ def teardown
+ Grit.debug = @old_debug
+ Grit.logger = @old_logger
+ end
+
+ def test_uses_stdout_logger_by_default
+ assert_equal STDOUT, Grit.logger.instance_variable_get(:@logdev).dev
+ end
+
+ def test_can_override_logger
+ my_logger = Logger.new(io = StringIO.new)
+ Grit.logger = my_logger
+ assert_equal my_logger, Grit.logger
+ end
+
+ def test_logs_to_specified_logger
+ Grit.logger = Logger.new(io = StringIO.new)
+ Grit.log 'hi mom'
+ io.rewind
+ assert io.read.include?('hi mom')
+ end
+
+end

0 comments on commit 2581238

Please sign in to comment.