Project

General

Profile

Defect #44440 ยป unify-scm-path-regexp.patch

Takenori TAKAKI, 2026-09-15 08:20

View differences:

app/models/repository.rb
433 433
  end
434 434

  
435 435
  def self.scm_available
436
    scm_client_available && Redmine::Configuration["scm_#{scm_name.to_s.downcase}_path_regexp"].present?
436
    scm_client_available && scm_path_regexp.present?
437
  end
438

  
439
  def self.scm_path_regexp
440
    # Uses name.demodulize, not scm_name, which each adapter overrides as its display label.
441
    Redmine::Configuration["scm_#{name.demodulize.downcase}_path_regexp"]
437 442
  end
438 443

  
439 444
  def set_as_default?
......
499 504
  # Validates repository url based against an optional regular expression
500 505
  # that can be set in the Redmine configuration file.
501 506
  def validate_repository_path(attribute=:url)
502
    regexp = Redmine::Configuration["scm_#{scm_name.to_s.downcase}_path_regexp"]
507
    regexp = self.class.scm_path_regexp
503 508
    if changes[attribute] && regexp.present?
504 509
      regexp = regexp.to_s.strip.gsub('%project%') {Regexp.escape(project.try(:identifier).to_s)}
505 510
      unless Regexp.new("\\A#{regexp}\\z").match?(send(attribute).to_s)
app/views/settings/_repositories.html.erb
15 15
    <% text, value = (choice.is_a?(Array) ? choice : [choice, choice]) %>
16 16
    <% setting = :enabled_scm %>
17 17
    <% enabled = Setting.send(setting).include?(value) %>
18
    <% path_regexp = Redmine::Configuration["scm_#{choice.to_s.downcase}_path_regexp"].presence %>
18
    <% path_regexp = scm_class.scm_path_regexp.presence %>
19 19
    <tr>
20 20
      <td class="scm_name">
21 21
        <label>
lib/redmine/info.rb
53 53
        s << "SCM:\n"
54 54
        Redmine::Scm::Base.all.each do |scm|
55 55
          scm_class = "Repository::#{scm}".constantize
56
          config = "scm_#{scm.to_s.downcase}_path_regexp"
57 56
          if scm_class.scm_client_available
58
            paths = if Redmine::Configuration[config].present?
59
                      "Allowed Paths: #{Redmine::Configuration[config]}"
57
            paths = if scm_class.scm_path_regexp.present?
58
                      "Allowed Paths: #{scm_class.scm_path_regexp}"
60 59
                    else
61 60
                      "DISABLED: scm_#{scm.to_s.downcase}_path_regexp missing in configuration.yml"
62 61
                    end
test/unit/repository_test.rb
561 561
    assert_nil Repository.factory('Serializer')
562 562
    assert_nil Repository.factory('Query')
563 563
  end
564

  
565
  def test_scm_path_regexp_should_use_registered_scm_name
566
    Redmine::Configuration.with 'scm_subversion_path_regexp' => '/svn/.*' do
567
      assert_equal '/svn/.*', Repository::Subversion.scm_path_regexp
568
    end
569
  end
570

  
571
  def test_scm_path_regexp_should_use_registered_scm_name_even_if_scm_name_is_overridden
572
    Repository::Subversion.stubs(:scm_name).returns('Custom SCM Label')
573

  
574
    Redmine::Configuration.with 'scm_subversion_path_regexp' => '/svn/.*' do
575
      assert_equal '/svn/.*', Repository::Subversion.scm_path_regexp
576
    end
577
  end
564 578
end
    (1-1/1)