normalize commit hashes so they at least show 'anonymous' if no git user is set.

This commit is contained in:
rick
2010-08-16 07:36:32 -07:00
parent 763387979a
commit ee04dd84aa
3 changed files with 44 additions and 8 deletions
+3 -6
View File
@@ -143,12 +143,9 @@ module Precious
end
def commit_message
message = params[:message]
author_name = `git config --get user.name`.strip || 'Anonymous'
author_email = `git config --get user.email`.strip || 'anon@anon.com'
{ :message => message,
:name => author_name,
:email => author_email }
{ :message => params[:message],
:name => `git config --get user.name `.strip,
:email => `git config --get user.email`.strip }
end
end
end
+26 -2
View File
@@ -9,6 +9,12 @@ module Gollum
# Sets the file class used by all instances of this Wiki.
attr_writer :file_class
# Sets the default name for commits.
attr_accessor :default_committer_name
# Sets the default email for commits.
attr_accessor :default_committer_email
# Gets the page class used by all instances of this Wiki.
# Default: Gollum::Page.
def page_class
@@ -32,6 +38,8 @@ module Gollum
end
end
self.default_committer_name = 'Anonymous'
self.default_committer_email = 'anon@anon.com'
# The String base path to prefix to internal links. For example, when set
# to "/wiki", the page "Hobbit" will be linked as "/wiki/Hobbit". Defaults
@@ -115,7 +123,8 @@ module Gollum
#
# Returns the String SHA1 of the newly written version.
def write_page(name, format, data, commit = {})
map = {}
commit = normalize_commit(commit)
map = {}
if pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
end
@@ -144,6 +153,7 @@ module Gollum
#
# Returns the String SHA1 of the newly written version.
def update_page(page, name, format, data, commit = {})
commit = normalize_commit(commit)
pcommit = @repo.commit('master')
map = tree_map(pcommit.tree)
name ||= page.name
@@ -169,7 +179,7 @@ module Gollum
# page - The Gollum::Page to delete.
# commit - The commit Hash details:
# :message - The String commit message.
# :author - The String author full name.
# :name - The String author full name.
# :email - The String email address.
#
# Returns the String SHA1 of the newly written version.
@@ -331,5 +341,19 @@ module Gollum
(container || map).delete(name)
map
end
# Ensures a commit hash has all the required fields for a commit.
#
# commit - The commit Hash details:
# :message - The String commit message.
# :name - The String author full name.
# :email - The String email address.
#
# Returns the commit Hash
def normalize_commit(commit = {})
commit[:name] = self.class.default_committer_name if commit[:name].to_s.empty?
commit[:email] = self.class.default_committer_email if commit[:email].to_s.empty?
commit
end
end
end
+15
View File
@@ -38,6 +38,21 @@ context "Wiki" do
%w(Bilbo-Baggins.md Eye-Of-Sauron.md Home.textile My-Precious.md),
pages.map { |p| p.filename }.sort
end
test "normalizes commit hash" do
commit = {:message => 'abc'}
assert_equal({:message => 'abc', :name => 'Anonymous', :email => 'anon@anon.com'},
@wiki.normalize_commit(commit.dup))
commit[:name] = 'bob'
commit[:email] = ''
assert_equal({:message => 'abc', :name => 'bob', :email => 'anon@anon.com'},
@wiki.normalize_commit(commit.dup))
commit[:email] = 'foo@bar.com'
assert_equal({:message => 'abc', :name => 'bob', :email => 'foo@bar.com'},
@wiki.normalize_commit(commit.dup))
end
end
context "Wiki page previewing" do