diff --git a/lib/grit/git-ruby/repository.rb b/lib/grit/git-ruby/repository.rb index 07306a18..46b5bc62 100644 --- a/lib/grit/git-ruby/repository.rb +++ b/lib/grit/git-ruby/repository.rb @@ -467,6 +467,28 @@ def diff(commit1, commit2, options = {}) '' # one of the trees was bad or lcs isn't there - no diff end + def quick_what_changed(t1, t2, path, type) + changed = [] + + t1[type].each do |file, hsh| + t2_file = t2[type][file] rescue nil + full = File.join(path, file) + if !t2_file + changed << [full, 'added', hsh[:sha], nil] # not in parent + elsif (hsh[:sha] != t2_file[:sha]) + changed << [full, 'modified', hsh[:sha], t2_file[:sha]] # file changed + end + end if t1 + + t2[type].each do |file, hsh| + if !t1 || !t1[type][file] + changed << [File.join(path, file), 'removed', nil, hsh[:sha]] + end + end if t2 + + changed + end + # takes 2 tree shas and recursively walks them to find out what # files or directories have been modified in them and returns an # array of changes @@ -476,27 +498,14 @@ def diff(commit1, commit2, options = {}) # ] def quick_diff(tree1, tree2, path = '.', recurse = true) # handle empty trees - changed = [] return changed if tree1 == tree2 t1 = list_tree(tree1) if tree1 t2 = list_tree(tree2) if tree2 # finding files that are different - t1['blob'].each do |file, hsh| - t2_file = t2['blob'][file] rescue nil - full = File.join(path, file) - if !t2_file - changed << [full, 'added', hsh[:sha], nil] # not in parent - elsif (hsh[:sha] != t2_file[:sha]) - changed << [full, 'modified', hsh[:sha], t2_file[:sha]] # file changed - end - end if t1 - t2['blob'].each do |file, hsh| - if !t1 || !t1['blob'][file] - changed << [File.join(path, file), 'removed', nil, hsh[:sha]] - end - end if t2 + changed = quick_what_changed(t1, t2, path, 'blob') + + quick_what_changed(t1, t2, path, 'link') t1['tree'].each do |dir, hsh| t2_tree = t2['tree'][dir] rescue nil diff --git a/test/dot_git/logs/refs/heads/test/kouno b/test/dot_git/logs/refs/heads/test/kouno new file mode 100644 index 00000000..bd55cd8c --- /dev/null +++ b/test/dot_git/logs/refs/heads/test/kouno @@ -0,0 +1,2 @@ +0000000000000000000000000000000000000000 2d3acf90f35989df8f262dc50beadc4ee3ae1560 Vincent Bonmalais 1349255070 +1000 push +2d3acf90f35989df8f262dc50beadc4ee3ae1560 2e0f114810c4974a6cb12eeb04026de7b3f599b3 Vincent Bonmalais 1349255247 +1000 push diff --git a/test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff b/test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff new file mode 100644 index 00000000..ed64bf4d Binary files /dev/null and b/test/dot_git/objects/2a/ffb5512da280a18fc8ce7a1b1bb4e728fae7ff differ diff --git a/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 b/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 new file mode 100644 index 00000000..12a7568d --- /dev/null +++ b/test/dot_git/objects/2e/0f114810c4974a6cb12eeb04026de7b3f599b3 @@ -0,0 +1,2 @@ +xJ0@]+f/KKGoV*ܾ:^_86k"<9 O]K{@f;lC& 'Tr \ No newline at end of file diff --git a/test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b b/test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b new file mode 100644 index 00000000..c59b4eac Binary files /dev/null and b/test/dot_git/objects/71/47bcd75e1a18cab3c1dbfb4acbd24bb431c71b differ diff --git a/test/dot_git/objects/71/d12fa2dee43b5fd9a98e9023c04e6fb8882409 b/test/dot_git/objects/71/d12fa2dee43b5fd9a98e9023c04e6fb8882409 new file mode 100644 index 00000000..cd304a20 Binary files /dev/null and b/test/dot_git/objects/71/d12fa2dee43b5fd9a98e9023c04e6fb8882409 differ diff --git a/test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 b/test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 new file mode 100644 index 00000000..3a111fa3 Binary files /dev/null and b/test/dot_git/objects/7b/45d974a391bfd6a994f0d59656bab1ce0f4cb5 differ diff --git a/test/dot_git/objects/93/eae0e32c467e3aa59632520ded268b9c3562f0 b/test/dot_git/objects/93/eae0e32c467e3aa59632520ded268b9c3562f0 new file mode 100644 index 00000000..dd31e575 Binary files /dev/null and b/test/dot_git/objects/93/eae0e32c467e3aa59632520ded268b9c3562f0 differ diff --git a/test/dot_git/refs/heads/test/kouno b/test/dot_git/refs/heads/test/kouno new file mode 100644 index 00000000..4e8a8c06 --- /dev/null +++ b/test/dot_git/refs/heads/test/kouno @@ -0,0 +1 @@ +2e0f114810c4974a6cb12eeb04026de7b3f599b3 diff --git a/test/test_head.rb b/test/test_head.rb index 73a55484..97bbc585 100644 --- a/test/test_head.rb +++ b/test/test_head.rb @@ -8,7 +8,7 @@ def setup # inspect def test_inspect - head = @r.heads[1] + head = @r.heads[2] assert_equal %Q{#}, head.inspect end @@ -31,7 +31,7 @@ def test_submaster # heads with slashes def test_heads_with_slashes - head = @r.heads[3] + head = @r.heads[4] assert_equal %Q{#}, head.inspect end @@ -42,8 +42,8 @@ def test_is_head end def test_head_count - assert_equal 5, @r.heads.size - assert_equal 5, @r.head_count + assert_equal 6, @r.heads.size + assert_equal 6, @r.head_count end diff --git a/test/test_repo.rb b/test/test_repo.rb index 0aa6431b..8c35e638 100644 --- a/test/test_repo.rb +++ b/test/test_repo.rb @@ -83,7 +83,7 @@ def test_heads_should_return_array_of_head_objects def test_heads_should_populate_head_data @r = Repo.new(File.join(File.dirname(__FILE__), *%w[dot_git]), :is_bare => true) - head = @r.heads[1] + head = @r.heads[2] assert_equal 'test/master', head.name assert_equal '2d3acf90f35989df8f262dc50beadc4ee3ae1560', head.commit.id diff --git a/test/test_rubygit.rb b/test/test_rubygit.rb index 9a4f5a16..83f62ed7 100644 --- a/test/test_rubygit.rb +++ b/test/test_rubygit.rb @@ -71,6 +71,14 @@ def test_diff_remove assert_match 'index 0000000..2e3b0cb', out end + def test_diff_symlink + commit1 = '2d3acf90f35989df8f262dc50beadc4ee3ae1560' + commit2 = '2e0f114810c4974a6cb12eeb04026de7b3f599b3' + out = @git.diff({}, commit1, commit2) + assert_match "--- /dev/null\n+++ b/test/fixtures/symlink", out + assert_match "diff --git a/test/fixtures/symlink b/test/fixtures/symlink", out + assert_match "index 0000000..7b45d97", out + end def test_cat_file_contents_commit out = @git.cat_file({:p => true}, @commit_sha)