summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/scm/adapters/abstract_adapter.rb11
-rw-r--r--lib/redmine/scm/adapters/git_adapter.rb12
-rw-r--r--lib/redmine/scm/adapters/mercurial_adapter.rb9
3 files changed, 31 insertions, 1 deletions
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index 7f3b8093f..55d6d6163 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -176,7 +176,16 @@ module Redmine
(path[-1,1] == "/") ? path[0..-2] : path
end
- private
+ 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
info = self.info
info ? info.root_url : nil
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index 4f889d0b1..a04e5cb6a 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -380,6 +380,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 a3b672d26..d443ac0ce 100644
--- a/lib/redmine/scm/adapters/mercurial_adapter.rb
+++ b/lib/redmine/scm/adapters/mercurial_adapter.rb
@@ -281,6 +281,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