public
Fork of mojombo/grit
Description: Grit is a Ruby library for extracting information from a git repository in an object oriented manner.
Homepage: http://grit.rubyforge.org/
Clone URL: git://github.com/technoweenie/grit.git
allow Grit::Commit.diff to specify an optional array of paths
technoweenie (author)
Sun Feb 10 22:51:18 -0800 2008
commit  c9cf68fc61bd2634e90a4f6a12d88744e6297c4e
tree    4929b022c7094614b84a2533022c6dfa07a69ef6
parent  460b3216db32a55d07b1de0570bbb8427611b599
...
149
150
151
152
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
155
156
...
149
150
151
 
 
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
0
@@ -149,8 +149,24 @@ module Grit
0
       commits
0
     end
0
     
0
- def self.diff(repo, a, b = nil)
0
- text = repo.git.diff({:full_index => true}, a, b)
0
+ # Show diffs between two trees:
0
+ # +repo+ is the Repo
0
+ # +a+ is a named commit
0
+ # +b+ is an optional named commit. Passing an array assumes you
0
+ # wish to omit the second named commit and limit the diff to the
0
+ # given paths.
0
+ # +paths* is an array of paths to limit the diff.
0
+ #
0
+ # Returns Grit::Diff[] (baked)
0
+ def self.diff(repo, a, b = nil, paths = [])
0
+ if b.is_a?(Array)
0
+ paths = b
0
+ b = nil
0
+ end
0
+ paths.unshift("--") unless paths.empty?
0
+ paths.unshift(b) unless b.nil?
0
+ paths.unshift(a)
0
+ text = repo.git.diff({:full_index => true}, *paths)
0
       Diff.list_from_string(repo, text)
0
     end
0
 
...
28
29
30
31
 
32
33
34
...
47
48
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
51
52
...
28
29
30
 
31
32
33
34
...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
0
@@ -28,7 +28,7 @@ class TestCommit < Test::Unit::TestCase
0
   def test_diff
0
     # git diff --full-index 91169e1f5fa4de2eaea3f176461f5dc784796769 > test/fixtures/diff_p
0
     
0
- Git.any_instance.expects(:diff).returns(fixture('diff_p'))
0
+ Git.any_instance.expects(:diff).with({:full_index => true}, 'master').returns(fixture('diff_p'))
0
     diffs = Commit.diff(@r, 'master')
0
     
0
     assert_equal 15, diffs.size
0
@@ -47,6 +47,30 @@ class TestCommit < Test::Unit::TestCase
0
     assert_equal 'f733bce6b57c0e5e353206e692b0e3105c2527f4', diffs[5].b_commit.id
0
     assert_equal true, diffs[5].new_file
0
   end
0
+
0
+ def test_diff_with_two_commits
0
+ # git diff --full-index 59ddc32 13d27d5 > test/fixtures/diff_2
0
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5').returns(fixture('diff_2'))
0
+ diffs = Commit.diff(@r, '59ddc32', '13d27d5')
0
+
0
+ assert_equal 3, diffs.size
0
+ end
0
+
0
+ def test_diff_with_files
0
+ # git diff --full-index 59ddc32 -- lib > test/fixtures/diff_f
0
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '--', 'lib').returns(fixture('diff_f'))
0
+ diffs = Commit.diff(@r, '59ddc32', %w(lib))
0
+
0
+ assert_equal 1, diffs.size
0
+ end
0
+
0
+ def test_diff_with_two_commits_and_files
0
+ # git diff --full-index 59ddc32 13d27d5 -- lib > test/fixtures/diff_2f
0
+ Git.any_instance.expects(:diff).with({:full_index => true}, '59ddc32', '13d27d5', '--', 'lib').returns(fixture('diff_2f'))
0
+ diffs = Commit.diff(@r, '59ddc32', '13d27d5', %w(lib))
0
+
0
+ assert_equal 1, diffs.size
0
+ end
0
 
0
   # diffs
0
   def test_diffs

Comments

    No one has commented yet.