From 19325930a26474554bded4b6271dfa2e941543a4 Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Mon, 9 Jul 2012 11:40:11 +0100 Subject: [PATCH 1/3] Add a new file and sub-directory - 'Rivendell/Elrond.md' so we can test Sidebar/Header/Footer inheritance from parent directory. --- test/examples/lotr.git/logs/HEAD | 2 ++ test/examples/lotr.git/logs/refs/heads/master | 2 ++ .../1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 | Bin 0 -> 53 bytes .../27/680b0fce1abfbc528e7aa53d92645852d52eb6 | Bin 0 -> 378 bytes .../4e/023f460ce466e154ca09d8774c79ad5a53fc15 | Bin 0 -> 54 bytes .../62/9aa678272b017a4d136d35e77ac94d80b08dc2 | 1 + .../cf/ea406f5f77afc7fb673a43e97721234385b1bd | 2 ++ .../fb/c5dd7d807707b4a0a97c1182fecfef1eced5df | 1 + .../fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 | Bin 0 -> 379 bytes .../ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 | Bin 0 -> 210 bytes test/examples/lotr.git/refs/heads/master | 2 +- test/test_committer.rb | 2 +- test/test_git_access.rb | 2 +- test/test_wiki.rb | 4 ++-- 14 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 create mode 100644 test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 create mode 100644 test/examples/lotr.git/objects/4e/023f460ce466e154ca09d8774c79ad5a53fc15 create mode 100644 test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 create mode 100644 test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd create mode 100644 test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df create mode 100644 test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 create mode 100644 test/examples/lotr.git/objects/ff/6f7de62644369380ba73b4e4297c1a2d6f0b66 diff --git a/test/examples/lotr.git/logs/HEAD b/test/examples/lotr.git/logs/HEAD index 6cba614a..31a4e256 100644 --- a/test/examples/lotr.git/logs/HEAD +++ b/test/examples/lotr.git/logs/HEAD @@ -3,3 +3,5 @@ a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell 1309107565 +0200 commit: Test out whitespace with Sam 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 b16b3d9fad9d78e5a669e7f33d94c96da374eccd kristi 1336983525 -0700 push b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5c kristi 1336984025 -0700 push +b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley 1341830099 +0100 push +cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley 1341830833 +0100 push diff --git a/test/examples/lotr.git/logs/refs/heads/master b/test/examples/lotr.git/logs/refs/heads/master index 6cba614a..31a4e256 100644 --- a/test/examples/lotr.git/logs/refs/heads/master +++ b/test/examples/lotr.git/logs/refs/heads/master @@ -3,3 +3,5 @@ a8ad3c09dd842a3517085bfadd37718856dee813 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 Arran Cudbard-Bell 1309107565 +0200 commit: Test out whitespace with Sam 1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3 b16b3d9fad9d78e5a669e7f33d94c96da374eccd kristi 1336983525 -0700 push b16b3d9fad9d78e5a669e7f33d94c96da374eccd b0de6e794dfdc7ef3400e894225bfe23308aae5c kristi 1336984025 -0700 push +b0de6e794dfdc7ef3400e894225bfe23308aae5c cfea406f5f77afc7fb673a43e97721234385b1bd Darren Oakley 1341830099 +0100 push +cfea406f5f77afc7fb673a43e97721234385b1bd 629aa678272b017a4d136d35e77ac94d80b08dc2 Darren Oakley 1341830833 +0100 push diff --git a/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 b/test/examples/lotr.git/objects/1c/79ddc69707f7b164bc2ea58beb5d8965ff6bd0 new file mode 100644 index 0000000000000000000000000000000000000000..415ae116725982154502419de6e427ceb4f720c1 GIT binary patch literal 53 zcmV-50LuS(0V^p=O;s>9XD~D{Ff%bxaLp;o&r8wEO=0+-U;9kW#cXoJuHr3EG;5@E L^SRRiPxlZ4Hn|s` literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 b/test/examples/lotr.git/objects/27/680b0fce1abfbc528e7aa53d92645852d52eb6 new file mode 100644 index 0000000000000000000000000000000000000000..e0fb454fcf683c29417bfb879b4239304b469dd6 GIT binary patch literal 378 zcmV-=0fqi}0V^p=O;s>4He@g~FfcPQQEYF!db67`ac%NP!Cv765^Et{jSigD5tv+XNdLiAWo41hqvJwGoc zzlb5vWA&e~u+Wm$c^q<2`_`q#dYmtW8sd?ko2plmT2YdjlgjYx`TJlO1?^pqnyc>! zv++)vesfAH#30}NB9KA6CmC~AY8>wkQCvAIcyr}eOHCy?s6oD!x&cM0$(i}3V0W+D zCjVk?*pEaXuExMyCO<9jy#18{F)AptEHy7BH7AF`kICMR=SkYbkW-vD%6%%=Mg{*7 zg_;(em|LD%oT}iSn46xOs+XIZl9^bZnVre7EOK+1b(8MRQkNw83;W)S=`F4nf$E8O z%g--KEdqtwn_EV#`yRR~tlGMKw?XkFHt)%O%`jCSsfj5NRkbr@ZnmtAm}m2Ww^2!) YC%-l$vJ$2$I5Q9XD~D{Ff%bxaLp;o&r8wEO=0+b^loiKIs29cD{BOs{+)j> Mckb$a0A#omZ86Oj&;S4c literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 b/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 new file mode 100644 index 00000000..4b894d58 --- /dev/null +++ b/test/examples/lotr.git/objects/62/9aa678272b017a4d136d35e77ac94d80b08dc2 @@ -0,0 +1 @@ +xMJ1F])j0S4(ZTe& 187pP55PNߴ*jzAFDV&cUli8SGIp0KQb>0ХJ'zwL}ǕRއè4p#^?<2k%sec8Q*|vipb;z{bT\ \ No newline at end of file diff --git a/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd b/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd new file mode 100644 index 00000000..92192562 --- /dev/null +++ b/test/examples/lotr.git/objects/cf/ea406f5f77afc7fb673a43e97721234385b1bd @@ -0,0 +1,2 @@ +xN0EY+fjǏHF&jWcvWW::g*P 1΁CY` &"[k<3" ZOгѫ|ѽ.*iy} wtˆko/=[XRt# +}vt(Ŝ]-=)&)]/ \ No newline at end of file diff --git a/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df b/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df new file mode 100644 index 00000000..e931c46b --- /dev/null +++ b/test/examples/lotr.git/objects/fb/c5dd7d807707b4a0a97c1182fecfef1eced5df @@ -0,0 +1 @@ +xEN@ D+FKR$h:8NbENgTI wW8hɖBT|QK. ylU;dM18ʢ\&fMmA3qXxwLŧ6C8I?dzT͍d Tjf̱ 9]<7[ b#t'Ǭga.BaH\d%ܬ[ŧRv/b \ No newline at end of file diff --git a/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 b/test/examples/lotr.git/objects/fc/3eee516ff72dc9099ba00d4611eb02e5c9e634 new file mode 100644 index 0000000000000000000000000000000000000000..74cbd3c11782bfedd1846c5a85cde71301696e5d GIT binary patch literal 379 zcmV->0fhc|0V^p=O;s>4He@g~FfcPQQEYF!db67`ac%NP!Cv765^Et{jSigD5tv+XNdLiAWo41hqvJwGoc zzlb5vWA&e~u+Wm$c^q<2`_`q#dYmtW8sd?ko2plmT2YdjlgjYx`TJlO1?^pqnyc>! zv++)vesfAH#30}NB9KA6CmC~AY8>wkQCvAIcyr}eOHCy?s6oD!x&cM0$(i}3V0W+D zCjVk?*pEaXuExMyCO<9jy#18{F)AptEHy7BH7AEbrtFnP(rtHyM+Wk7VGxdM= z1*mDkiMi#O#iisd~AoDVd4onc0~P%OW?ISvTq4EOkkezp(GUnBL-Q5vZPc zxBUE))FM!*y}4z?y6>T@!m6#ycN-K>V)LHd*9=qTk(!tSQB^xb=4Q*ptEP> zH{+9*6YlPBuMXHI9E)Cr4P(3LvYgNCY=O)!D}|I6-Mal7A4&t) Mn|;^)0Ccfn0$4a|wEzGB literal 0 HcmV?d00001 diff --git a/test/examples/lotr.git/refs/heads/master b/test/examples/lotr.git/refs/heads/master index bd1b8af0..a19ee561 100644 --- a/test/examples/lotr.git/refs/heads/master +++ b/test/examples/lotr.git/refs/heads/master @@ -1 +1 @@ -b0de6e794dfdc7ef3400e894225bfe23308aae5c +629aa678272b017a4d136d35e77ac94d80b08dc2 diff --git a/test/test_committer.rb b/test/test_committer.rb index 494b12f5..57d8c2b8 100644 --- a/test/test_committer.rb +++ b/test/test_committer.rb @@ -50,7 +50,7 @@ context "Wiki" do end test "parents with default master ref" do - ref = 'b0de6e794dfdc7ef3400e894225bfe23308aae5c' + ref = '629aa678272b017a4d136d35e77ac94d80b08dc2' committer = Gollum::Committer.new(@wiki) assert_equal ref, committer.parents.first.sha end diff --git a/test/test_git_access.rb b/test/test_git_access.rb index 3cd8d0ac..df49b17d 100644 --- a/test/test_git_access.rb +++ b/test/test_git_access.rb @@ -18,7 +18,7 @@ context "GitAccess" do assert @access.ref_map.empty? assert @access.tree_map.empty? @access.tree 'master' - assert_equal({"master"=>"b0de6e794dfdc7ef3400e894225bfe23308aae5c"}, @access.ref_map) + assert_equal({"master"=>"629aa678272b017a4d136d35e77ac94d80b08dc2"}, @access.ref_map) @access.tree '1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3' map = @access.tree_map['1db89ebba7e2c14d93b94ff98cfa3708a4f0d4e3'] diff --git a/test/test_wiki.rb b/test/test_wiki.rb index 63303f67..5fa7c0f6 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -54,7 +54,7 @@ context "Wiki" do test "list pages" do pages = @wiki.pages assert_equal \ - ['Bilbo-Baggins.md', 'Boromir.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'], + ['Bilbo-Baggins.md', 'Boromir.md', 'Elrond.md', 'Eye-Of-Sauron.md', 'Home.textile', 'My-Precious.md', 'Samwise Gamgee.mediawiki'], pages.map { |p| p.filename }.sort end @@ -66,7 +66,7 @@ context "Wiki" do end test "counts pages" do - assert_equal 6, @wiki.size + assert_equal 7, @wiki.size end test "text_data" do From 50e494e8e93b9fb8f8554ff2120ecb581523560f Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Mon, 9 Jul 2012 12:10:41 +0100 Subject: [PATCH 2/3] Make pages inherit their sidebar/header/footer from parent directories regardless of the current 'page_file_dir' of the wiki. refs #413 (https://github.com/github/gollum/issues/413) --- lib/gollum/frontend/app.rb | 9 ++++----- lib/gollum/page.rb | 6 ++++-- lib/gollum/wiki.rb | 9 +++++++-- test/test_page.rb | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index 4e0cf4f9..c0368caf 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -126,7 +126,7 @@ module Precious redirect "/#{page.escaped_url_path}" end - + get '/create/*' do wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) @name = params[:splat].first @@ -136,7 +136,7 @@ module Precious mustache :create end end - + post '/create' do name = params[:page] path = sanitize_empty_params(params[:path]) @@ -294,9 +294,8 @@ module Precious def show_page_or_file(fullpath) path = extract_path(fullpath) name = extract_name(fullpath) - # This breaks headers, footers, and sidebars. - # wiki_options = settings.wiki_options.merge({ :page_file_dir => path }) - wiki = Gollum::Wiki.new(settings.gollum_path, settings.wiki_options) + wiki_options = settings.wiki_options.merge({ :page_file_dir => path }) + wiki = Gollum::Wiki.new(settings.gollum_path, wiki_options) if page = wiki.page(name) @page = page diff --git a/lib/gollum/page.rb b/lib/gollum/page.rb index f93dc19d..3ec3305d 100644 --- a/lib/gollum/page.rb +++ b/lib/gollum/page.rb @@ -434,7 +434,9 @@ module Gollum end # Loads a sub page. Sub page names (footers, headers, sidebars) are prefixed with - # an underscore to distinguish them from other Pages. + # an underscore to distinguish them from other Pages. If there is not one within + # the current directory, starts walking up the directory tree to try and find one + # within parent directories. # # name - String page name. # @@ -447,7 +449,7 @@ module Gollum dirs = self.path.split('/') dirs.pop - map = @wiki.tree_map_for(@wiki.ref) + map = @wiki.tree_map_for(@wiki.ref, true) while !dirs.empty? if page = find_page_in_tree(map, name, dirs.join('/')) page.parent_page = self diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 089b25d5..11c156c8 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -682,10 +682,15 @@ module Gollum # listing is cached based on its actual commit SHA. # # ref - A String ref that is either a commit SHA or references one. + # ignore_page_file_dir - Boolean, if true, searches all files within the git repo, regardless of dir/subdir # # Returns an Array of BlobEntry instances. - def tree_map_for(ref) - @access.tree(ref) + def tree_map_for(ref, ignore_page_file_dir=false) + if ignore_page_file_dir + GitAccess.new(path, nil, @repo_is_bare).tree(ref) + else + @access.tree(ref) + end rescue Grit::GitRuby::Repository::NoSuchShaFound [] end diff --git a/test/test_page.rb b/test/test_page.rb index b10d4c1d..fb41a792 100644 --- a/test/test_page.rb +++ b/test/test_page.rb @@ -195,3 +195,36 @@ context "Page" do assert_equal "/foo", Gollum::BlobEntry.normalize_dir("/foo") end end + +context "within a sub-directory" do + setup do + @wiki = Gollum::Wiki.new(testpath("examples/lotr.git"), { :page_file_dir => 'Rivendell' }) + end + + test "get existing page" do + page = @wiki.page('Elrond') + assert_equal Gollum::Page, page.class + assert page.raw_data =~ /^# Elrond\n\nElrond/ + assert_equal 'Rivendell/Elrond.md', page.path + assert_equal :markdown, page.format + assert_equal @wiki.repo.commits.first.id, page.version.id + end + + test "should not get page from parent dir" do + page = @wiki.page('Bilbo Baggins') + assert_equal nil, page + end + + test "should inherit header/footer/sidebar pages from parent directories" do + page = @wiki.page('Elrond') + + assert_equal Gollum::Page, page.sidebar.class + assert_equal Gollum::Page, page.header.class + assert_equal Gollum::Page, page.footer.class + + assert page.sidebar.raw_data =~ /^Lord of the Rings/ + assert page.header.raw_data =~ /^Hobbits/ + assert page.footer.raw_data =~ /^Lord of the Rings/ + end +end + From 1cc9d7b6474e88837d947dc570a6b1beac768869 Mon Sep 17 00:00:00 2001 From: Darren Oakley Date: Mon, 9 Jul 2012 13:01:40 +0100 Subject: [PATCH 3/3] Slight optimisations... - only create a new GitAccess object if the wiki does not have a @page_file_dir directive - memoize the new GitAccess object --- lib/gollum/wiki.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index 11c156c8..c3967df9 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -686,8 +686,9 @@ module Gollum # # Returns an Array of BlobEntry instances. def tree_map_for(ref, ignore_page_file_dir=false) - if ignore_page_file_dir - GitAccess.new(path, nil, @repo_is_bare).tree(ref) + if ignore_page_file_dir && !@page_file_dir.nil? + @root_access ||= GitAccess.new(path, nil, @repo_is_bare) + @root_access.tree(ref) else @access.tree(ref) end