add method for getting the reverse diff without a page path

This commit is contained in:
rick
2011-01-13 13:32:15 -08:00
parent 710741813b
commit 002fe8d409
2 changed files with 30 additions and 26 deletions
+17 -2
View File
@@ -580,7 +580,7 @@ module Gollum
# Creates a reverse diff for the given SHAs on the given Gollum::Page.
#
# page - The Gollum::Page to scope the patch to.
# page - The Gollum::Page to scope the patch to, or a String Path.
# sha1 - String SHA1 of the earlier parent if two SHAs are given,
# or the child.
# sha2 - Optional String SHA1 of the child.
@@ -588,7 +588,22 @@ module Gollum
# Returns a String of the reverse Diff to apply.
def full_reverse_diff_for(page, sha1, sha2 = nil)
sha1, sha2 = "#{sha1}^", sha1 if sha2.nil?
repo.git.native(:diff, {:R => true}, sha1, sha2, '--', page.path)
args = [{:R => true}, sha1, sha2]
if page
args << '--' << (page.respond_to?(:path) ? page.path : page.to_s)
end
repo.git.native(:diff, *args)
end
# Creates a reverse diff for the given SHAs.
#
# sha1 - String SHA1 of the earlier parent if two SHAs are given,
# or the child.
# sha2 - Optional String SHA1 of the child.
#
# Returns a String of the reverse Diff to apply.
def full_reverse_diff(sha1, sha2 = nil)
full_reverse_diff_for(nil, sha1, sha2)
end
# Ensures a commit hash has all the required fields for a commit.
+13 -24
View File
@@ -61,30 +61,6 @@ context "Wiki" do
@wiki.normalize_commit(commit.dup))
end
#test "#tree_map_for caches ref and tree" do
# assert @wiki.ref_map.empty?
# assert @wiki.tree_map.empty?
# @wiki.tree_map_for 'master'
# assert_equal({"master"=>"60f12f4254f58801b9ee7db7bca5fa8aeefaa56b"}, @wiki.ref_map)
#
# map = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b']
# assert_equal 'Bilbo-Baggins.md', map[0].path
# assert_equal '', map[0].dir
# assert_equal map[0].path, map[0].name
# assert_equal 'Mordor/Eye-Of-Sauron.md', map[3].path
# assert_equal '/Mordor', map[3].dir
# assert_equal 'Eye-Of-Sauron.md', map[3].name
#end
#
#test "#tree_map_for only caches tree for commit" do
# assert @wiki.tree_map.empty?
# @wiki.tree_map_for '60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'
# assert @wiki.ref_map.empty?
#
# entry = @wiki.tree_map['60f12f4254f58801b9ee7db7bca5fa8aeefaa56b'][0]
# assert_equal 'Bilbo-Baggins.md', entry.path
#end
test "text_data" do
wiki = Gollum::Wiki.new(testpath("examples/yubiwa.git"))
if String.instance_methods.include?(:encoding)
@@ -97,6 +73,19 @@ context "Wiki" do
assert_equal page.raw_data, page.text_data
end
end
test "gets reverse diff" do
diff = @wiki.full_reverse_diff('a8ad3c09dd842a3517085bfadd37718856dee813')
assert_match "b/Mordor/_Sidebar.md", diff
assert_match "b/_Sidebar.md", diff
end
test "gets reverse diff for a page" do
diff = @wiki.full_reverse_diff_for('_Sidebar.md', 'a8ad3c09dd842a3517085bfadd37718856dee813')
regex = /b\/Mordor\/\_Sidebar\.md/
assert_match "b/_Sidebar.md", diff
assert_no_match regex, diff
end
end
context "Wiki page previewing" do