lib/gitdocs/server.rb in gitdocs-0.4.13 vs lib/gitdocs/server.rb in gitdocs-0.4.14
- old
+ new
@@ -70,10 +70,11 @@
gd = gds[idx]
halt 404 if gd.nil?
file_path = URI.unescape(request.path_info)
file_ext = File.extname(file_path)
expanded_path = File.expand_path(".#{file_path}", gd.root)
+ message_file = File.expand_path(".gitmessage~", gd.root)
halt 400 unless expanded_path[/^#{Regexp.quote(gd.root)}/]
parent = File.dirname(file_path)
parent = '' if parent == '/'
parent = nil if parent == '.'
locals = {:idx => idx, :parent => parent, :root => gd.root, :file_path => expanded_path, :nav_state => nil }
@@ -81,10 +82,11 @@
mode = request.params['mode']
if mode == 'meta' # Meta
halt 200, { 'Content-Type' => 'application/json' }, [gd.file_meta(file_path).to_json]
elsif mode == 'save' # Saving
File.open(expanded_path, 'w') { |f| f.print request.params['data'] }
+ File.open(message_file, 'w') { |f| f.print request.params['message'] } unless request.params['message'] == ''
redirect! "/" + idx.to_s + file_path
elsif mode == 'upload' # Uploading
halt 404 unless file = request.params['file']
tempfile, filename = file[:tempfile], file[:filename]
FileUtils.mv(tempfile.path, File.expand_path(filename, expanded_path))
@@ -99,9 +101,15 @@
end
render! "dir", :layout => 'app', :locals => locals.merge(:contents => contents, :rendered_readme => rendered_readme)
elsif mode == "revisions" # list revisions
revisions = gd.file_revisions(file_path)
render! "revisions", :layout => 'app', :locals => locals.merge(:revisions => revisions)
+ elsif mode == "revert" # revert file
+ if revision = request.params['revision']
+ File.open(message_file, 'w') { |f| f.print "Reverting '#{file_path}' to #{revision}" }
+ gd.file_revert(file_path, revision)
+ end
+ redirect! "/" + idx.to_s + file_path
elsif mode == 'delete' # delete file
FileUtils.rm(expanded_path)
redirect! "/" + idx.to_s + parent
elsif mode == 'edit' && mime.match(%r{text/}) # edit file
contents = File.read(expanded_path)
\ No newline at end of file