Defect #44440
closedInconsistent scm_TYPE_path_regexp key: scm_name in Repository, registered adapter name elsewhere
Description
Since r24864, an adapter without scm_TYPE_path_regexp in config/configuration.yml is shown as DISABLED and treated as unavailable. The key is built in two different ways:
lib/redmine/info.rbandapp/views/settings/_repositories.html.erbuse the registered adapter name:"scm_#{scm.to_s.downcase}_path_regexp"Repository.scm_availableandRepository#validate_repository_pathusescm_name:"scm_#{scm_name.to_s.downcase}_path_regexp"
Bundled adapters are unaffected, because their scm_name downcases to their registered name (Repository::Cvs.scm_name is "CVS", registered as "Cvs"). The keys diverge when an adapter overrides scm_name with a different display label, as third-party adapters commonly do.
Steps to reproduce¶
For an adapter registered as CustomScm whose scm_name is "Custom SCM":
- Open "Administration > Information" with no key set. It reports
DISABLED: scm_customscm_path_regexp missing in configuration.yml. - Add
scm_customscm_path_regexptoconfig/configuration.ymlas instructed, and restart. - Open "Administration > Settings > Repositories".
Actual behavior¶
Setting the key the message asked for changes nothing but the display. The "Path to repository" column now shows the configured regexp, and the information page reports it as an allowed path, but on the same row the adapter's checkbox is still disabled and it cannot be enabled.
Repository.scm_available looks up scm_custom scm_path_regexp (note the space) rather than the key named in the message. That lookup returns nil, so the adapter stays unavailable, Setting.enabled_scm drops it, and it is never offered when creating a repository. The spaced key cannot reasonably be written in configuration.yml either.
Repository#validate_repository_path reads the same spaced key, so for a repository of this type the regexp is never applied to the URL: the value is nil, regexp.present? is false, and the check is skipped.
Expected behavior¶
The key named in the DISABLED message is the one used for availability and validation, so that setting it makes the adapter selectable and applies the regexp to repository URLs.
Possible fix¶
Derive the key from the registered adapter name in Repository.scm_available and Repository#validate_repository_path as well, leaving scm_name as a display label. Key names for bundled adapters would be unchanged, so this is backward compatible and no existing configuration.yml needs to be edited.
Files
Updated by Takenori TAKAKI about 1 month ago
The attached patch fixes this by deriving the scm_TYPE_path_regexp configuration key from the repository class name (name.demodulize), which corresponds to the adapter's registered identifier, rather than from the overridable scm_name display label.
Repository.scm_available and Repository#validate_repository_path previously built this key directly from scm_name. They now call a new Repository.scm_path_regexp class method. The other two call sites, lib/redmine/info.rb and app/views/settings/_repositories.html.erb, also use this method, centralizing the lookup. Configuration keys for the bundled adapters remain unchanged.
Updated by Go MAEDA about 1 month ago
- Target version set to 7.1.0
Setting the target version to 7.1.0.
Updated by Marius BĂLTEANU about 1 month ago
- Assignee set to Holger Just
Looks good to me. Holger Just, can you take a look, please?
Updated by Holger Just about 1 month ago
- Assignee changed from Holger Just to Marius BĂLTEANU
Looks good to me, too. Thanks!
Updated by Marius BĂLTEANU about 1 month ago
- Status changed from New to Closed
- Target version deleted (
7.1.0) - Resolution set to Fixed