lib/gitdocs/runner.rb in gitdocs-0.4.13 vs lib/gitdocs/runner.rb in gitdocs-0.4.14
- old
+ new
@@ -107,14 +107,20 @@
error("There was a problem synchronizing this gitdoc", "A problem occurred in #{@root}:\n#{out}")
end
end
def push_changes
+ message_file = File.expand_path(".gitmessage~", @root)
+ if File.exist? message_file
+ message = File.read message_file
+ File.delete message_file
+ else
+ message = 'Auto-commit from gitdocs'
+ end
sh 'find . -type d -regex ``./[^.].*'' -empty -exec touch \'{}/.gitignore\' \;'
sh 'git add .'
- # TODO make this message nicer
- sh "git commit -a -m'Auto-commit from gitdocs'" unless sh("git status -s").strip.empty?
+ sh "git commit -a -m #{ShellTools.escape(message)}" unless sh("git status -s").strip.empty?
if @current_revision.nil? || sh('git status')[/branch is ahead/]
out, code = sh_with_code("git push #{@current_remote} #{@current_branch}")
if code.success?
changes = get_latest_changes
info("Pushed #{changes.size} change#{changes.size == 1 ? '' : 's'}", "`#{@root}' has been pushed")
@@ -195,9 +201,19 @@
file = file.gsub(%r{^/}, '')
content = sh_string("git show #{ref}:#{ShellTools.escape(file)}")
tmp_path = File.expand_path(File.basename(file), Dir.tmpdir)
File.open(tmp_path, 'w') { |f| f.puts content }
tmp_path
+ end
+
+ # Revert a file to a particular revision
+ def file_revert(file, ref)
+ if file_revisions(file).map {|r| r[:commit]}.include? ref
+ file = file.gsub(%r{^/}, '')
+ full_path = File.expand_path(file, @root)
+ content = File.read(file_revision_at(file, ref))
+ File.open(full_path, 'w') { |f| f.puts content }
+ end
end
def valid?
out, status = sh_with_code "git status"
@root.present? && status.success?