diff --git a/lib/gollum/file.rb b/lib/gollum/file.rb index 20ceeec8..38f53e75 100644 --- a/lib/gollum/file.rb +++ b/lib/gollum/file.rb @@ -46,13 +46,14 @@ module Gollum # # Returns a Gollum::File or nil if the file could not be found. def find(name, version) - if commit = @wiki.repo.commit(version) - if (blob = commit.tree / name) && blob.is_a?(Grit::Blob) - @blob = blob - @path = name - @version = commit - self - end + checked = name.downcase + map = @wiki.tree_map_for(version) + sha = @wiki.ref_map[version] || version + if pair = map.detect { |(path, _)| path == checked } + @path = name + @blob = Grit::Blob.create(@wiki.repo, :id => pair.last, :name => ::File.basename(@path)) + @version = Grit::Commit.create(@wiki.repo, :id => sha) + self end end end diff --git a/test/test_file.rb b/test/test_file.rb index bcb507c4..56ded7f9 100644 --- a/test/test_file.rb +++ b/test/test_file.rb @@ -11,9 +11,12 @@ context "File" do end test "existing file" do - file = @wiki.file("Mordor/todo.txt") + commit = @wiki.repo.commits.first + file = @wiki.file("Mordor/todo.txt") assert_equal "[ ] Write section on Ents\n", file.raw_data - assert_equal @wiki.repo.commits.first.id, file.version.id + assert_equal 'todo.txt', file.name + assert_equal commit.id, file.version.id + assert_equal commit.author.name, file.version.author.name end test "accessing tree" do