add revert action
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user