From 979d89a23f423823cddae0b48f766612bf82e076 Mon Sep 17 00:00:00 2001 From: rick Date: Thu, 9 Dec 2010 17:19:18 -0800 Subject: [PATCH] add revert action --- lib/gollum/frontend/app.rb | 24 ++++++++++++++++++++++++ test/test_app.rb | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index bde1be57..d98c9e54 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -82,6 +82,30 @@ module Precious end end + post '/revert/:page/*' do + wiki = Gollum::Wiki.new(settings.gollum_path) + @name = params[:page] + @page = wiki.page(@name) + shas = params[:splat].first.split("/") + sha1 = shas.shift + sha2 = shas.shift + sha1 = "#{sha1}^" if sha2 + + if wiki.revert_page(@page, sha1, sha2, commit_message) + redirect "/#{CGI.escape(@name)}" + else + if sha2 + sha1.chomp!('^') + else + sha2, sha1 = sha1, "#{sha1}^" + end + @versions = [sha1, sha2] + diffs = wiki.repo.diff(@versions.first, @versions.last, @page.path) + @diff = diffs.first + mustache :compare + end + end + post '/preview' do wiki = Gollum::Wiki.new(settings.gollum_path) @name = "Preview" diff --git a/test/test_app.rb b/test/test_app.rb index 8c5610ab..fd9dd580 100644 --- a/test/test_app.rb +++ b/test/test_app.rb @@ -97,6 +97,43 @@ context "Frontend" do assert last_response.ok? end + test "reverts single commit" do + page1 = @wiki.page('B') + + post "/revert/B/7c45b5f16ff3bae2a0063191ef832701214d4df5" + follow_redirect! + assert last_response.ok? + + @wiki.clear_cache + page2 = @wiki.page('B') + assert_not_equal page1.version.sha, page2.version.sha + assert_equal "INITIAL", page2.raw_data.strip + end + + test "reverts multiple commits" do + page1 = @wiki.page('A') + + post "/revert/A/302a5491a9a5ba12c7652ac831a44961afa312d2/b26b791cb7917c4f37dd9cb4d1e0efb24ac4d26f" + follow_redirect! + assert last_response.ok? + + @wiki.clear_cache + page2 = @wiki.page('A') + assert_not_equal page1.version.sha, page2.version.sha + assert_equal "INITIAL", page2.raw_data.strip + end + + test "cannot revert conflicting commit" do + page1 = @wiki.page('A') + + post "/revert/A/302a5491a9a5ba12c7652ac831a44961afa312d2" + assert last_response.ok? + + @wiki.clear_cache + page2 = @wiki.page('A') + assert_equal page1.version.sha, page2.version.sha + end + def app Precious::App end