From bf37f44970e89f92c7a9dab3fa19be4e13fa7078 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 30 Aug 2010 18:09:14 -0700 Subject: [PATCH] pull default name/email for commits from wiki repo's git config --- lib/gollum/frontend/app.rb | 10 ++++------ lib/gollum/wiki.rb | 16 ++++++++++++++-- test/test_wiki.rb | 6 ++++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index bdc9f1e4..0c88a8f0 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -58,7 +58,7 @@ module Precious format = params[:format].intern 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}" end @@ -70,7 +70,7 @@ module Precious format = params[:format].intern begin - wiki.write_page(name, format, params[:content], commit_message(wiki)) + wiki.write_page(name, format, params[:content], commit_message) redirect "/#{name}" rescue Gollum::DuplicatePageError => e @message = "Duplicate page: #{e.message}" @@ -149,10 +149,8 @@ module Precious end end - def commit_message(wiki) - { :message => params[:message], - :name => wiki.repo.config['user.name'], - :email => wiki.repo.config['user.email'] } + def commit_message + { :message => params[:message] } end end end diff --git a/lib/gollum/wiki.rb b/lib/gollum/wiki.rb index c84650cb..4770bec3 100644 --- a/lib/gollum/wiki.rb +++ b/lib/gollum/wiki.rb @@ -441,11 +441,23 @@ module Gollum # # 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[:name] = default_committer_name if commit[:name].to_s.empty? + commit[:email] = default_committer_email if commit[:email].to_s.empty? commit 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 # listing is cached based on its actual commit SHA. # diff --git a/test/test_wiki.rb b/test/test_wiki.rb index 004e48b8..51cd287b 100644 --- a/test/test_wiki.rb +++ b/test/test_wiki.rb @@ -45,12 +45,14 @@ context "Wiki" do test "normalizes commit hash" do 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)) commit[:name] = 'bob' 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)) commit[:email] = 'foo@bar.com'