diff options
author | Go MAEDA <maeda@farend.jp> | 2021-04-23 01:44:28 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-04-23 01:44:28 +0000 |
commit | 1d4042d262c46d623b2cc36465552094fe46a312 (patch) | |
tree | 2d5fd383f45d9963d90e6990a76382fc97520e80 /lib/redmine | |
parent | 79a6a77c5b8c51484f5dd86e583159b1cd4ae783 (diff) | |
download | redmine-1d4042d262c46d623b2cc36465552094fe46a312.tar.gz redmine-1d4042d262c46d623b2cc36465552094fe46a312.zip |
Merged r20962 from trunk to 4.1-stable (#35085).
git-svn-id: http://svn.redmine.org/redmine/branches/4.1-stable@20964 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine')
-rw-r--r-- | lib/redmine/scm/adapters/abstract_adapter.rb | 8 | ||||
-rw-r--r-- | lib/redmine/scm/adapters/git_adapter.rb | 12 | ||||
-rw-r--r-- | lib/redmine/scm/adapters/mercurial_adapter.rb | 9 |
3 files changed, 29 insertions, 0 deletions
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 14f8f09c4..226c8a148 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -178,6 +178,14 @@ module Redmine (path[-1,1] == "/") ? path[0..-2] : path end + def valid_name?(name) + return true if name.nil? + return true if name.is_a?(Integer) && name > 0 + return true if name.is_a?(String) && name =~ /\A[0-9]*\z/ + + false + end + private def retrieve_root_url diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index ddb1055f3..d833369b6 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -388,6 +388,18 @@ module Redmine nil end + def valid_name?(name) + return false unless name.is_a?(String) + + return false if name.start_with?('-', '/', 'refs/heads/', 'refs/remotes/') + return false if name == 'HEAD' + + git_cmd ['show-ref', '--heads', '--tags', '--quiet', '--', name] + true + rescue ScmCommandAborted + false + end + class Revision < Redmine::Scm::Adapters::Revision # Returns the readable identifier def format_identifier diff --git a/lib/redmine/scm/adapters/mercurial_adapter.rb b/lib/redmine/scm/adapters/mercurial_adapter.rb index fd3c80de3..1ef808f03 100644 --- a/lib/redmine/scm/adapters/mercurial_adapter.rb +++ b/lib/redmine/scm/adapters/mercurial_adapter.rb @@ -291,6 +291,15 @@ module Redmine Annotate.new end + def valid_name?(name) + return false unless name.nil? || name.is_a?(String) + + # Mercurials names don't need to be checked further as its CLI + # interface is restrictive enough to reject any invalid names on its + # own. + true + end + class Revision < Redmine::Scm::Adapters::Revision # Returns the readable identifier def format_identifier |