Feature #6515 » mercurial_hgrc_support.diff
| app/models/repository/mercurial.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require 'redmine/scm/adapters/mercurial_adapter'
|
||
|
require 'redmine/scm/adapters/mercurial/hgrc_support'
|
||
|
class Repository::Mercurial < Repository
|
||
|
include HgrcSupport
|
||
|
# sort changesets by revision number
|
||
|
has_many :changesets, :order => "#{Changeset.table_name}.id DESC", :foreign_key => 'repository_id'
|
||
| lib/redmine/scm/adapters/mercurial/hgrc_support.rb | ||
|---|---|---|
|
require 'ini'
|
||
|
module HgrcSupport
|
||
|
def self.included(base)
|
||
|
base.after_save :save_hgrc
|
||
|
end
|
||
|
|
||
|
attr_reader :hgrc_hooks_issues_update
|
||
|
attr_accessor :hgrc_web_contact
|
||
|
attr_accessor :hgrc_web_description
|
||
|
attr_accessor :hgrc_web_style
|
||
|
|
||
|
def hgrc_hooks_issues_update=(value)
|
||
|
if ['0', '1'].include? value.to_s
|
||
|
@hgrc_hooks_issues_update = value
|
||
|
elsif value == true
|
||
|
@hgrc_hooks_issues_update = 1
|
||
|
else
|
||
|
@hgrc_hooks_issues_update = 0
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def load_hgrc
|
||
|
ini = Ini.new(File.join(url, '.hg', 'hgrc'))
|
||
|
#web
|
||
|
ini['web'] = {} if ini['web'].nil?
|
||
|
@hgrc_web_contact = ini['web']['contact']
|
||
|
@hgrc_web_description = ini['web']['description']
|
||
|
@hgrc_web_style = ini['web']['style']
|
||
|
#hooks
|
||
|
ini['hooks'] = {} if ini['hooks'].nil?
|
||
|
if !ini['hooks']['changegroup.redmine'].nil? && !ini['hooks']['changegroup.redmine'].empty?
|
||
|
@hgrc_hooks_issues_update = 1
|
||
|
else
|
||
|
@hgrc_hooks_issues_update = 0
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
def save_hgrc
|
||
|
ini = Ini.new(File.join(url, '.hg', 'hgrc'))
|
||
|
#web
|
||
|
ini['web'] = {} if ini['web'].nil?
|
||
|
ini['web']['contact'] = @hgrc_web_contact
|
||
|
ini['web']['description'] = @hgrc_web_description
|
||
|
ini['web']['style'] = @hgrc_web_style
|
||
|
#hooks
|
||
|
ini['hooks'] = {} if ini['hooks'].nil?
|
||
|
if @hgrc_hooks_issues_update.to_i == 1
|
||
|
ini['hooks']['changegroup.redmine'] = "cd #{RAILS_ROOT} && ruby script/runner \"Repository.find(#{self[:id]}).fetch_changesets\" -e #{RAILS_ENV}"
|
||
|
elsif !ini['hooks']['changegroup.redmine'].nil? && !ini['hooks']['changegroup.redmine'].empty?
|
||
|
ini['hooks'].delete('changegroup.redmine')
|
||
|
end
|
||
|
ini.comment = "Generated with Redmine.\n"
|
||
|
#save
|
||
|
ini.update()
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- 4
- Next »