Class: Redmine::Scm::Adapters::AbstractAdapter

Inherits:
Object
  • Object
show all
Includes:
Utils::Shell
Defined in:
lib/redmine/scm/adapters/abstract_adapter.rb

Overview

:nodoc:

Since:

  • 0.5.1

Defined Under Namespace

Classes: ScmCommandAborted

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, root_url = nil, login = nil, password = nil, path_encoding = nil) ⇒ AbstractAdapter

Returns a new instance of AbstractAdapter



71
72
73
74
75
76
77
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 71

def initialize(url, root_url=nil, =nil, password=nil,
               path_encoding=nil)
  @url = url
  @login =  if  && !.empty?
  @password = (password || "") if @login
  @root_url = root_url.blank? ? retrieve_root_url : root_url
end

Class Method Details

.client_availableObject

Since:

  • 1.2.0



65
66
67
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 65

def client_available
  true
end

.client_commandObject

Since:

  • 1.2.0



32
33
34
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 32

def client_command
  ""
end

.client_versionObject

Returns the version of the scm client Eg: [1, 5, 0] or [] if unknown

Since:

  • 0.8.0



46
47
48
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 46

def client_version
  []
end

.client_version_above?(v, options = {}) ⇒ Boolean

Returns true if the current client version is above or equals the given one If option is :unknown is set to true, it will return true if the client version is unknown

Returns:

  • (Boolean)

Since:

  • 0.8.0



61
62
63
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 61

def client_version_above?(v, options={})
  ((client_version <=> v) >= 0) || (client_version.empty? && options[:unknown])
end

.client_version_stringObject

Returns the version string of the scm client Eg: '1.5.0' or 'Unknown version' if unknown

Since:

  • 0.8.0



52
53
54
55
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 52

def client_version_string
  v = client_version || 'Unknown version'
  v.is_a?(Array) ? v.join('.') : v.to_s
end

.shell_quote(str) ⇒ Object

Since:

  • 1.2.0



36
37
38
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 36

def shell_quote(str)
  Redmine::Utils::Shell.shell_quote str
end

.shell_quote_commandObject

Since:

  • 1.2.2



40
41
42
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 40

def shell_quote_command
  Redmine::Utils::Shell.shell_quote_command client_command
end

Instance Method Details

#adapter_nameObject



79
80
81
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 79

def adapter_name
  'Abstract'
end

#branchesObject

Since:

  • 0.9.0



130
131
132
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 130

def branches
  return nil
end

#cat(path, identifier = nil) ⇒ Object



154
155
156
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 154

def cat(path, identifier=nil)
  return nil
end

#default_branchObject

Since:

  • 0.9.0



138
139
140
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 138

def default_branch
  return nil
end

#diff(path, identifier_from, identifier_to = nil) ⇒ Object



150
151
152
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 150

def diff(path, identifier_from, identifier_to=nil)
  return nil
end

#entries(path = nil, identifier = nil, options = {}) ⇒ Object

Returns an Entries collection or nil if the given path doesn't exist in the repository



126
127
128
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 126

def entries(path=nil, identifier=nil, options={})
  return nil
end

#entry(path = nil, identifier = nil) ⇒ Object

Returns the entry identified by path and revision identifier or nil if entry doesn't exist in the repository



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 110

def entry(path=nil, identifier=nil)
  parts = path.to_s.split(%r{[\/\\]}).select {|n| !n.blank?}
  search_path = parts[0..-2].join('/')
  search_name = parts[-1]
  if search_path.blank? && search_name.blank?
    # Root entry
    Entry.new(:path => '', :kind => 'dir')
  else
    # Search for the entry in the parent directory
    es = entries(search_path, identifier)
    es ? es.detect {|e| e.name == search_name} : nil
  end
end

#infoObject

get info about the svn repository



104
105
106
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 104

def info
  return nil
end

#path_encodingObject

Since:

  • 1.2.0



99
100
101
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 99

def path_encoding
  nil
end

#properties(path, identifier = nil) ⇒ Object

Since:

  • 0.8.0



142
143
144
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 142

def properties(path, identifier=nil)
  return nil
end

#revisions(path = nil, identifier_from = nil, identifier_to = nil, options = {}) ⇒ Object



146
147
148
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 146

def revisions(path=nil, identifier_from=nil, identifier_to=nil, options={})
  return nil
end

#root_urlObject



91
92
93
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 91

def root_url
  @root_url
end

#supports_annotate?Boolean

Returns:

  • (Boolean)

Since:

  • 0.6.1



87
88
89
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 87

def supports_annotate?
  respond_to?('annotate')
end

#supports_cat?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 83

def supports_cat?
  true
end

#tagsObject

Since:

  • 0.9.0



134
135
136
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 134

def tags
  return nil
end

#urlObject



95
96
97
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 95

def url
  @url
end

#with_leading_slash(path) ⇒ Object



158
159
160
161
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 158

def with_leading_slash(path)
  path ||= ''
  (path[0,1]!="/") ? "/#{path}" : path
end

#with_trailling_slash(path) ⇒ Object

Since:

  • 0.8.0



163
164
165
166
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 163

def with_trailling_slash(path)
  path ||= ''
  (path[-1,1] == "/") ? path : "#{path}/"
end

#without_leading_slash(path) ⇒ Object

Since:

  • 0.8.0



168
169
170
171
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 168

def without_leading_slash(path)
  path ||= ''
  path.gsub(%r{^/+}, '')
end

#without_trailling_slash(path) ⇒ Object

Since:

  • 0.8.0



173
174
175
176
# File 'lib/redmine/scm/adapters/abstract_adapter.rb', line 173

def without_trailling_slash(path)
  path ||= ''
  (path[-1,1] == "/") ? path[0..-2] : path
end