pull default name/email for commits from wiki repo's git config

This commit is contained in:
rick
2010-08-30 18:09:14 -07:00
parent 847e6c00a4
commit bf37f44970
3 changed files with 22 additions and 10 deletions
+4 -6
View File
@@ -58,7 +58,7 @@ module Precious
format = params[:format].intern format = params[:format].intern
name = params[:rename] if params[:rename] name = params[:rename] if params[:rename]
wiki.update_page(page, name, format, params[:content], commit_message(wiki)) wiki.update_page(page, name, format, params[:content], commit_message)
redirect "/#{Gollum::Page.cname name}" redirect "/#{Gollum::Page.cname name}"
end end
@@ -70,7 +70,7 @@ module Precious
format = params[:format].intern format = params[:format].intern
begin begin
wiki.write_page(name, format, params[:content], commit_message(wiki)) wiki.write_page(name, format, params[:content], commit_message)
redirect "/#{name}" redirect "/#{name}"
rescue Gollum::DuplicatePageError => e rescue Gollum::DuplicatePageError => e
@message = "Duplicate page: #{e.message}" @message = "Duplicate page: #{e.message}"
@@ -149,10 +149,8 @@ module Precious
end end
end end
def commit_message(wiki) def commit_message
{ :message => params[:message], { :message => params[:message] }
:name => wiki.repo.config['user.name'],
:email => wiki.repo.config['user.email'] }
end end
end end
end end
+14 -2
View File
@@ -441,11 +441,23 @@ module Gollum
# #
# Returns the commit Hash # Returns the commit Hash
def normalize_commit(commit = {}) def normalize_commit(commit = {})
commit[:name] = self.class.default_committer_name if commit[:name].to_s.empty? commit[:name] = default_committer_name if commit[:name].to_s.empty?
commit[:email] = self.class.default_committer_email if commit[:email].to_s.empty? commit[:email] = default_committer_email if commit[:email].to_s.empty?
commit commit
end end
# Gets the default name for commits.
def default_committer_name
@default_committer_name ||= \
@repo.config['user.name'] || self.class.default_committer_name
end
# Gets the default email for commits.
def default_committer_email
@default_committer_email ||= \
@repo.config['user.email'] || self.class.default_committer_email
end
# Finds a full listing of files and their blob SHA for a given ref. Each # Finds a full listing of files and their blob SHA for a given ref. Each
# listing is cached based on its actual commit SHA. # listing is cached based on its actual commit SHA.
# #
+4 -2
View File
@@ -45,12 +45,14 @@ context "Wiki" do
test "normalizes commit hash" do test "normalizes commit hash" do
commit = {:message => 'abc'} commit = {:message => 'abc'}
assert_equal({:message => 'abc', :name => 'Anonymous', :email => 'anon@anon.com'}, name = @wiki.repo.config['user.name']
email = @wiki.repo.config['user.email']
assert_equal({:message => 'abc', :name => name, :email => email},
@wiki.normalize_commit(commit.dup)) @wiki.normalize_commit(commit.dup))
commit[:name] = 'bob' commit[:name] = 'bob'
commit[:email] = '' commit[:email] = ''
assert_equal({:message => 'abc', :name => 'bob', :email => 'anon@anon.com'}, assert_equal({:message => 'abc', :name => 'bob', :email => email},
@wiki.normalize_commit(commit.dup)) @wiki.normalize_commit(commit.dup))
commit[:email] = 'foo@bar.com' commit[:email] = 'foo@bar.com'