relevance-grit 0.8.1 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.8.3 / 2008-07-07
2
+ * Capture stderr and log if debug is true (rsanheim)
3
+
4
+ == 0.8.2 / 2008-06-27
5
+ * Allow user provided logger (rsanheim)
6
+
1
7
  == 0.8.0 / 2008-04-24
2
8
  * Lots of fixes and additions
3
9
 
data/grit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "grit"
3
- s.version = "0.8.1"
3
+ s.version = "0.8.3"
4
4
  s.date = "2008-04-24"
5
5
  s.summary = "Object model interface to a git repo"
6
6
  s.email = "tom@rubyisawesome.com"
data/lib/grit/git.rb CHANGED
@@ -56,16 +56,18 @@ module Grit
56
56
 
57
57
  call = "#{prefix}#{Git.git_binary} --git-dir='#{self.git_dir}' #{cmd.to_s.gsub(/_/, '-')} #{(opt_args + ext_args).join(' ')}#{postfix}"
58
58
  Grit.log(call) if Grit.debug
59
- response = timeout ? sh(call) : wild_sh(call)
59
+ response, err = timeout ? sh(call) : wild_sh(call)
60
60
  Grit.log(response) if Grit.debug
61
+ Grit.log(err) if Grit.debug
61
62
  response
62
63
  end
63
64
 
64
65
  def sh(command)
65
- ret, pid = nil, nil
66
- Open4.popen4(command) do |id, _, io, _|
66
+ ret, pid, err = nil, nil, nil
67
+ Open4.popen4(command) do |id, _, stdout, stderr|
67
68
  pid = id
68
- ret = Timeout.timeout(self.class.git_timeout) { io.read }
69
+ ret = Timeout.timeout(self.class.git_timeout) { stdout.read }
70
+ err = stderr.read
69
71
  @bytes_read += ret.size
70
72
 
71
73
  if @bytes_read > 5242880 # 5.megabytes
@@ -74,9 +76,9 @@ module Grit
74
76
  raise GitTimeout.new(command, bytes)
75
77
  end
76
78
  end
77
- ret
79
+ [ret, err]
78
80
  rescue Errno::ECHILD
79
- ret
81
+ [ret, err]
80
82
  rescue Object => e
81
83
  Process.kill('KILL', pid) rescue nil
82
84
  bytes = @bytes_read
@@ -85,12 +87,14 @@ module Grit
85
87
  end
86
88
 
87
89
  def wild_sh(command)
88
- ret = nil
89
- Open4.popen4(command) {|pid, _, io, _|
90
- ret = io.read
90
+ ret, err = nil, nil
91
+ Open4.popen4(command) {|pid, _, stdout, stderr|
92
+ ret = stdout.read
93
+ err = stderr.read
91
94
  }
95
+ [ret, err]
92
96
  rescue Errno::ECHILD
93
- ret
97
+ [ret, err]
94
98
  end
95
99
 
96
100
  # Transform Ruby style options into git command line options
data/lib/grit.rb CHANGED
@@ -28,8 +28,11 @@ require 'grit/repo'
28
28
  require 'grit/index'
29
29
 
30
30
  module Grit
31
+
31
32
  class << self
33
+ # Set +debug+ to true to log all git calls and responses
32
34
  attr_accessor :debug
35
+ # The standard +logger+ for debugging git calls - this defaults to a plain STDOUT logger
33
36
  attr_accessor :logger
34
37
  def log(str)
35
38
  logger.debug { str }
data/test/test_git.rb CHANGED
@@ -5,10 +5,28 @@ class TestGit < Test::Unit::TestCase
5
5
  @git = Git.new(File.join(File.dirname(__FILE__), *%w[..]))
6
6
  end
7
7
 
8
+ def teardown
9
+ Grit.debug = false
10
+ end
11
+
8
12
  def test_method_missing
9
13
  assert_match(/^git version [\w\.]*$/, @git.version)
10
14
  end
11
15
 
16
+ def test_logs_stderr
17
+ Grit.debug = true
18
+ Grit.stubs(:log)
19
+ Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
20
+ @git.bad
21
+ end
22
+
23
+ def testl_logs_stderr_when_skipping_timeout
24
+ Grit.debug = true
25
+ Grit.stubs(:log)
26
+ Grit.expects(:log).with(includes("git: 'bad' is not a git-command"))
27
+ @git.bad :timeout => false
28
+ end
29
+
12
30
  def test_transform_options
13
31
  assert_equal ["-s"], @git.transform_options({:s => true})
14
32
  assert_equal ["-s '5'"], @git.transform_options({:s => 5})
@@ -46,7 +64,7 @@ class TestGit < Test::Unit::TestCase
46
64
 
47
65
  def test_works_fine_if_quick
48
66
  output = 'output'
49
- Open4.expects(:popen4).yields( nil, nil, mock(:read => output), nil )
67
+ Open4.expects(:popen4).yields( nil, nil, mock(:read => output), stub(:read => nil) )
50
68
  assert_equal output, @git.something
51
69
  end
52
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relevance-grit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner