redmine_scm_patch.diff
app/views/repositories/_form.html.erb | ||
---|---|---|
1 | 1 |
<%= error_messages_for 'repository' %> |
2 | ||
3 |
<div class="box tabular"> |
|
2 |
<head> |
|
3 |
<script> |
|
4 |
$(function() { |
|
5 |
$("#tabs").tabs({ |
|
6 |
create: function( event, ui ) {advanced(ui.panel);}, |
|
7 |
activate: function(event, ui) { |
|
8 |
advanced(ui.newPanel); |
|
9 |
} |
|
10 |
}); |
|
11 |
}); |
|
12 |
</script> |
|
13 |
</head> |
|
14 |
<div class="box tabular" id="tabs"> |
|
15 |
<ul> |
|
16 |
<li><a href="#normal">New Repository</a></li> |
|
17 |
<li><a href="#advanced">Advanced Configuration</a></li> |
|
18 |
</ul> |
|
19 |
<div id="normal"> |
|
20 |
</div> |
|
21 |
<div id="advanced"> |
|
22 |
</div> |
|
4 | 23 |
<p> |
5 | 24 |
<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %> |
6 | 25 |
<% if @repository && ! @repository.class.scm_available %> |
... | ... | |
16 | 35 |
<%= l(:text_length_between, :min => 1, :max => Repository::IDENTIFIER_MAX_LENGTH) %> <%= l(:text_repository_identifier_info).html_safe %> |
17 | 36 |
</em> |
18 | 37 |
<% end %> |
38 |
<!--<label for="repository_advanced" alt="Manually input the URL" title="Manually input the URL" >Advanced</label> |
|
39 |
<input name="repository_advanced" type="hidden" value="0" /><input id="repository_advanced" name="repository_advanced" type="checkbox" value="1" onclick="advanced()" alt="Manually input the URL" title="Manually input the URL"/> --> |
|
19 | 40 |
</p> |
20 | 41 | |
21 | 42 |
<% button_disabled = true %> |
22 | 43 |
<% if @repository %> |
23 | 44 |
<% button_disabled = ! @repository.class.scm_available %> |
24 |
<%= repository_field_tags(f, @repository) %> |
|
45 |
|
|
46 | ||
47 | ||
48 |
<script> |
|
49 |
function generateUrl(id,max,force) |
|
50 |
{ |
|
51 |
//Subversion and Git support only. |
|
52 |
var active = $("#tabs div.ui-tabs-panel[aria-hidden='false']").attr("id"); |
|
53 |
|
|
54 |
var identifier = id; // .apply() to call function with arguments |
|
55 | ||
56 |
if(active != 'advanced' || force) |
|
57 |
{ |
|
58 |
if (identifier.length == 0) |
|
59 |
{ |
|
60 |
|
|
61 |
if(document.getElementById('repository_scm').value == 'Subversion') |
|
62 |
{ |
|
63 |
identifier = 'file://<% path = SubversionCreator.default_path(@project.identifier) %><%= path %>'; |
|
64 |
return identifier; |
|
65 |
} |
|
66 |
if(document.getElementById('repository_scm').value == 'Git') |
|
67 |
{ |
|
68 |
identifier = '<% path = GitCreator.default_path(@project.identifier) %><%= path %>'; |
|
69 |
return identifier; |
|
70 |
} |
|
71 |
|
|
72 |
} |
|
73 |
else |
|
74 |
{ |
|
75 |
if(document.getElementById('repository_scm').value == 'Subversion') |
|
76 |
{ |
|
77 |
identifier = 'file://<% path = SubversionCreator.default_path(@project.identifier)%><%= path %>'+'.'+identifier |
|
78 |
return identifier; |
|
79 |
} |
|
80 |
if(document.getElementById('repository_scm').value == 'Git') |
|
81 |
{ |
|
82 |
identifier = '<% fullpath = GitCreator.default_path("") |
|
83 |
fullpath.slice!(".git") |
|
84 |
path = fullpath %><%= path %>'+identifier+'.git'; |
|
85 |
return identifier; |
|
86 |
} |
|
87 |
} |
|
88 | ||
89 |
} |
|
90 | ||
91 |
return $('#repository_url').val(); |
|
92 | ||
93 |
} |
|
94 | ||
95 |
var maxlength = parseInt($('#repository_url').attr('maxlength')); |
|
96 |
function seturl() |
|
97 |
{ |
|
98 |
$('#repository_url').val(generateUrl($('#repository_identifier').val(), maxlength, false)); |
|
99 | ||
100 |
} |
|
101 |
function seturlforce() |
|
102 |
{ |
|
103 |
$('#repository_url').val(generateUrl($('#repository_identifier').val(), maxlength, true)); |
|
104 |
advanced($("#tabs div.ui-tabs-panel[aria-hidden='false']")); |
|
105 |
} |
|
106 |
function advanced(pan) |
|
107 |
{ |
|
108 |
seturl(); |
|
109 |
var active = pan.attr("id"); |
|
110 |
//console.log(pan); |
|
111 |
if(active != 'advanced') |
|
112 |
{ |
|
113 |
var el = document.getElementById('repository_url'); |
|
114 |
var el2 = document.getElementById('repository_login'); |
|
115 |
var el3 = document.getElementById('repository_password'); |
|
116 |
var el4 = document.getElementById('repository_group'); |
|
117 |
if(el) el.style.display = "none"; |
|
118 |
if(el2) el2.style.display = "none"; |
|
119 |
if(el3) el3.style.display = "none"; |
|
120 |
if(el4) el4.style.display = "none"; |
|
121 |
var labels = document.getElementsByTagName('label'); |
|
122 |
for(var i = 0; i < labels.length; i ++) |
|
123 |
{ |
|
124 |
var attr = labels[i].getAttribute('for'); |
|
125 |
if(el && attr == el.id || el2 && attr == el2.id || el3 && attr == el3.id) |
|
126 |
{ |
|
127 |
labels[i].style.display = "none"; |
|
128 |
} |
|
129 |
} |
|
130 |
var inputs = document.getElementsByTagName('input'); |
|
131 |
for(var i = 0; i < inputs.length; i ++) |
|
132 |
{ |
|
133 |
var attr = inputs[i].getAttribute('value'); |
|
134 |
if(attr == '<%=l(:button_create_new_repository)%>') |
|
135 |
{ |
|
136 |
$(inputs[i]).appendTo('#submission'); |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
else |
|
141 |
{ |
|
142 |
var el = document.getElementById('repository_url'); |
|
143 |
var el2 = document.getElementById('repository_login'); |
|
144 |
var el3 = document.getElementById('repository_password'); |
|
145 |
var el4 = document.getElementById('repository_group'); |
|
146 |
|
|
147 |
if(el) el.style.display = "initial"; |
|
148 |
if(el2) el2.style.display = "initial"; |
|
149 |
if(el3) el3.style.display = "initial"; |
|
150 |
if(el4) el4.style.display = "initial"; |
|
151 |
var labels = document.getElementsByTagName('label'); |
|
152 |
for(var i = 0; i < labels.length; i ++) |
|
153 |
{ |
|
154 |
var attr = labels[i].getAttribute('for'); |
|
155 |
if(el && attr === el.id || el2 && attr == el2.id || el3 && attr == el3.id) |
|
156 |
{ |
|
157 |
labels[i].style.display = "initial"; |
|
158 |
} |
|
159 |
} |
|
160 |
var inputs = document.getElementsByTagName('input'); |
|
161 |
for(var i = 0; i < inputs.length; i ++) |
|
162 |
{ |
|
163 |
var attr = inputs[i].getAttribute('value'); |
|
164 |
if(attr == '<%=l(:button_create_new_repository)%>') |
|
165 |
{ |
|
166 |
$(inputs[i]).appendTo('#submission'); |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
</script> |
|
172 | ||
173 | ||
174 | ||
175 |
<span id="repository_group"><%= repository_field_tags(f, @repository) %></span> |
|
176 |
<script> |
|
177 |
|
|
178 |
var el = document.getElementById('repository_url'); |
|
179 |
if(el) |
|
180 |
{ |
|
181 |
el.style.display = "none"; |
|
182 |
var labels = document.getElementsByTagName('label'); |
|
183 |
for(var i = 0; i < labels.length; i ++) |
|
184 |
{ |
|
185 |
var attr = labels[i].getAttribute('for'); |
|
186 |
if(attr === el.id) |
|
187 |
{ |
|
188 |
labels[i].style.display = "none"; |
|
189 |
} |
|
190 |
} |
|
191 |
//$('#repository_identifier').oninput=clickbox; |
|
192 |
el = document.getElementById('repository_identifier'); |
|
193 |
if (el.addEventListener) |
|
194 |
{ |
|
195 |
el.addEventListener('input', seturl, true); |
|
196 |
} |
|
197 |
else if (el.attachEvent) |
|
198 |
{ |
|
199 |
el.attachEvent('oninput', seturl); |
|
200 |
} |
|
201 |
} |
|
202 |
//------------------------------ |
|
203 |
if(el) |
|
204 |
{ |
|
205 |
el = document.getElementById('repository_scm'); |
|
206 |
if (el.addEventListener) |
|
207 |
{ |
|
208 |
el.addEventListener('change', seturlforce, true); |
|
209 |
} |
|
210 |
else if (el.attachEvent) |
|
211 |
{ |
|
212 |
el.attachEvent('onchange', seturlforce); |
|
213 |
} |
|
214 |
} |
|
215 | ||
216 |
</script> |
|
25 | 217 |
<% end %> |
26 | 218 |
</div> |
27 | 219 | |
220 | ||
28 | 221 |
<p> |
222 |
<% if @repository && !@repository.new_record? %> |
|
29 | 223 |
<%= submit_tag(@repository.new_record? ? l(:button_create) : l(:button_save), :id => 'repository_save', :disabled => button_disabled) %> |
30 |
<%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %> |
|
224 |
<% end %> |
|
225 | ||
226 |
<span id = "submission"></span> |
|
227 |
<%= link_to l(:button_cancel), settings_project_path(@project, :tab => 'repositories') %> |
|
31 | 228 |
</p> |
config/scm.yml | ||
---|---|---|
15 | 15 |
svnadmin: /usr/bin/svnadmin |
16 | 16 |
url: svn |
17 | 17 |
git: |
18 |
path: /opt/gitolite/repositories |
|
19 |
git: /opt/redmine/plugins/redmine_git_hosting/bin/run_git_cmd_as_gitolite_user |
|
20 |
options: --bare |
|
21 |
url: git |
|
22 |
update_server_info: true |
|
23 |
git_ext: true |
|
24 |
append: trunk |
|
25 |
mercurial: |
|
26 |
path: /var/lib/mercurial |
|
27 |
hg: /usr/bin/hg |
|
28 |
bazaar: |
|
29 |
path: /var/lib/bazaar |
|
30 |
bzr: /usr/bin/bzr |
|
31 |
init: init-repository |
|
32 |
log_encoding: UTF-8 |
|
33 |
github: |
|
34 |
path: /var/lib/github |
|
35 |
api: |
|
36 |
token: 36857b12efbccc64ce725ea8674fab6ecbd05c03 |
|
37 |
register_hook: true |
|
38 | ||
39 |
development: |
|
40 |
deny_delete: false |
|
41 |
auto_create: false |
|
42 |
force_repository: false |
|
43 |
pre_create: /usr/local/bin/pre-create.sh |
|
44 |
post_create: /usr/local/bin/post-create.sh |
|
45 |
pre_delete: /usr/local/bin/pre-delete.sh |
|
46 |
post_delete: /usr/local/bin/post-delete.sh |
|
47 |
max_repos: 0 |
|
48 |
only_creator: false |
|
49 |
allow_add_local: false |
|
50 |
allow_pickup: false |
|
51 |
svn: |
|
52 |
path: /var/lib/svn |
|
53 |
svnadmin: /usr/bin/svnadmin |
|
54 |
url: svn |
|
55 |
git: |
|
18 | 56 |
path: /var/lib/git |
19 | 57 |
git: /usr/bin/git |
20 | 58 |
options: --bare |
... | ... | |
35 | 73 |
api: |
36 | 74 |
token: 36857b12efbccc64ce725ea8674fab6ecbd05c03 |
37 | 75 |
register_hook: true |
38 | ||
39 |
development: |
config/scm.yml~ | ||
---|---|---|
1 |
production: |
|
2 |
deny_delete: false |
|
3 |
auto_create: false |
|
4 |
force_repository: false |
|
5 |
pre_create: /usr/local/bin/pre-create.sh |
|
6 |
post_create: /usr/local/bin/post-create.sh |
|
7 |
pre_delete: /usr/local/bin/pre-delete.sh |
|
8 |
post_delete: /usr/local/bin/post-delete.sh |
|
9 |
max_repos: 0 |
|
10 |
only_creator: false |
|
11 |
allow_add_local: false |
|
12 |
allow_pickup: false |
|
13 |
svn: |
|
14 |
path: /var/lib/svn |
|
15 |
svnadmin: /usr/bin/svnadmin |
|
16 |
url: svn |
|
17 |
git: |
|
18 |
path: /var/lib/git |
|
19 |
git: /usr/bin/git |
|
20 |
options: --bare |
|
21 |
url: http://git.myhost.com |
|
22 |
update_server_info: true |
|
23 |
git_ext: true |
|
24 |
append: trunk |
|
25 |
mercurial: |
|
26 |
path: /var/lib/mercurial |
|
27 |
hg: /usr/bin/hg |
|
28 |
bazaar: |
|
29 |
path: /var/lib/bazaar |
|
30 |
bzr: /usr/bin/bzr |
|
31 |
init: init-repository |
|
32 |
log_encoding: UTF-8 |
|
33 |
github: |
|
34 |
path: /var/lib/github |
|
35 |
api: |
|
36 |
token: 36857b12efbccc64ce725ea8674fab6ecbd05c03 |
|
37 |
register_hook: true |
|
38 | ||
39 |
development: |
|
40 |
deny_delete: false |
|
41 |
auto_create: false |
|
42 |
force_repository: false |
|
43 |
pre_create: /usr/local/bin/pre-create.sh |
|
44 |
post_create: /usr/local/bin/post-create.sh |
|
45 |
pre_delete: /usr/local/bin/pre-delete.sh |
|
46 |
post_delete: /usr/local/bin/post-delete.sh |
|
47 |
max_repos: 0 |
|
48 |
only_creator: false |
|
49 |
allow_add_local: false |
|
50 |
allow_pickup: false |
|
51 |
svn: |
|
52 |
path: /var/lib/svn |
|
53 |
svnadmin: /usr/bin/svnadmin |
|
54 |
url: svn |
|
55 |
git: |
|
56 |
path: /var/lib/git |
|
57 |
git: /usr/bin/git |
|
58 |
options: --bare |
|
59 |
url: http://git.myhost.com |
|
60 |
update_server_info: true |
|
61 |
git_ext: true |
|
62 |
append: trunk |
|
63 |
mercurial: |
|
64 |
path: /var/lib/mercurial |
|
65 |
hg: /usr/bin/hg |
|
66 |
bazaar: |
|
67 |
path: /var/lib/bazaar |
|
68 |
bzr: /usr/bin/bzr |
|
69 |
init: init-repository |
|
70 |
log_encoding: UTF-8 |
|
71 |
github: |
|
72 |
path: /var/lib/github |
|
73 |
api: |
|
74 |
token: 36857b12efbccc64ce725ea8674fab6ecbd05c03 |
|
75 |
register_hook: true |
lib/creator/#scm_creator.rb# | ||
---|---|---|
1 |
class SCMCreator |
|
2 |
include Redmine::I18n |
|
3 | ||
4 |
class << self |
|
5 | ||
6 |
# factory-like method that determines the actual creator |
|
7 |
def interface(repository) |
|
8 |
if repository.is_a?(Repository) |
|
9 |
type = repository.class.name |
|
10 |
elsif repository.is_a?(Class) |
|
11 |
type = repository.name |
|
12 |
else |
|
13 |
type = repository.to_s |
|
14 |
end |
|
15 |
Object.const_get("#{type.demodulize}Creator") |
|
16 |
rescue NameError |
|
17 |
nil |
|
18 |
end |
|
19 | ||
20 |
# returns config id used in scm.yml and ScmConfig |
|
21 |
def scm_id |
|
22 |
if self.name =~ %r{^(.+)Creator$} |
|
23 |
$1.downcase |
|
24 |
else |
|
25 |
nil |
|
26 |
end |
|
27 |
end |
|
28 | ||
29 |
# returns true if SCM is enabled |
|
30 |
def enabled? |
|
31 |
false |
|
32 |
end |
|
33 | ||
34 |
# returns true if SCM creates local repository |
|
35 |
def local? |
|
36 |
true |
|
37 |
end |
|
38 | ||
39 |
# returns configuration from scm.yml |
|
40 |
def options |
|
41 |
@options ||= ScmConfig[scm_id] |
|
42 |
end |
|
43 | ||
44 |
# can be used to sanitize attribute values |
|
45 |
def sanitize(attributes) |
|
46 |
attributes |
|
47 |
end |
|
48 | ||
49 |
# returns local path used to access repository locally (with optional /.git/ etc) |
|
50 |
def access_url(path, repository = nil) |
|
51 |
if options['append'] |
|
52 |
if Redmine::Platform.mswin? |
|
53 |
"#{access_root_url(path, repository)}\\#{options['append']}" |
|
54 |
else |
|
55 |
"#{access_root_url(path, repository)}/#{options['append']}" |
|
56 |
end |
|
57 |
else |
|
58 |
access_root_url(path, repository) |
|
59 |
end |
|
60 |
end |
|
61 | ||
62 |
# returns local path used to access repository locally |
|
63 |
def access_root_url(path, repository = nil) |
|
64 |
path |
|
65 |
end |
|
66 | ||
67 |
# returns local path |
|
68 |
def path(identifier) |
|
69 |
if Redmine::Platform.mswin? |
|
70 |
# Assuming path is in Windows style (contains \'s) |
|
71 |
"#{options['path']}\\#{identifier}" |
|
72 |
else |
|
73 |
"#{options['path']}/#{identifier}" |
|
74 |
end |
|
75 |
end |
|
76 | ||
77 |
# returns url which can be used to access the repository externally |
|
78 |
def external_url(repository, regexp = %r{^https?://}) |
|
79 |
if options['url'] && name = repository_name(repository.root_url) |
|
80 |
if options['url'] =~ regexp |
|
81 |
url = "#{options['url']}/#{name}" |
|
82 |
else |
|
83 |
url = "#{Setting.protocol}://#{Setting.host_name}/#{options['url']}/#{name}" |
|
84 |
end |
|
85 |
else |
|
86 |
nil |
|
87 |
end |
|
88 |
end |
|
89 | ||
90 |
# constructs default path using project identifier |
|
91 |
def default_path(identifier) |
|
92 |
path(identifier) |
|
93 |
end |
|
94 | ||
95 |
# get path of existing repository |
|
96 |
def existing_path(identifier, repository = nil) |
|
97 |
if File.directory?(default_path(identifier)) |
|
98 |
default_path(identifier) |
|
99 |
else |
|
100 |
nil |
|
101 |
end |
|
102 |
end |
|
103 | ||
104 |
# extracts repository name from path |
|
105 |
def repository_name(path) |
|
106 |
base = Redmine::Platform.mswin? ? options['path'].gsub(%r{\\}, "/") : options['path'] |
|
107 |
matches = Regexp.new("^#{Regexp.escape(base)}/([^/]+)/?$").match(path) |
|
108 |
matches ? matches[1] : nil |
|
109 |
end |
|
110 | ||
111 |
# compares repository names (was created for multiple repositories support) |
|
112 |
def belongs_to_project?(name, identifier) |
|
113 |
name =~ %r{^#{Regexp.escape(identifier)}(\..+)?$} |
|
114 |
end |
|
115 | ||
116 |
# returns format of repository path which is displayed in the form as a default value |
|
117 |
def repository_format |
|
118 |
path = Redmine::Platform.mswin? ? options['path'].gsub(%r{\\}, "/") : options['path'] |
|
119 |
"#{path}/<#{l(:label_repository_format)}>/" |
|
120 |
end |
|
121 | ||
122 |
# checks if repository already exists (was created for Git which can add .git extension) |
|
123 |
def repository_exists?(identifier) |
|
124 |
File.directory?(default_path(identifier)) |
|
125 |
end |
|
126 | ||
127 |
# creates repository |
|
128 |
def create_repository(path, repository = nil) |
|
129 |
false |
|
130 |
end |
|
131 | ||
132 |
# removes repository |
|
133 |
def delete_repository(path) |
|
134 |
# See: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/fileutils/rdoc/FileUtils.html#method-c-remove_entry_secure |
|
135 |
FileUtils.remove_entry_secure(path, true) |
|
136 |
end |
|
137 | ||
138 |
# executes custom scripts |
|
139 |
def execute(script, path, project) |
|
140 |
if File.executable?(script) |
|
141 |
project.custom_field_values.each do |custom_value| |
|
142 |
name = custom_value.custom_field.name.gsub(%r{[^a-z0-9]+}i, '_').upcase |
|
143 |
ENV["SCM_CUSTOM_FIELD_#{name}"] = custom_value.value unless name.empty? |
|
144 |
end |
|
145 |
system(script, path, scm_id, project.identifier) |
|
146 |
else |
|
147 |
Rails.logger.warn "cannot find/execute: #{script}" |
|
148 |
end |
|
149 |
end |
|
150 | ||
151 |
# initializes required properties of repository (used for Bazaar which requires log_encoding) |
|
152 |
def init_repository(repository) |
|
153 |
end |
|
154 | ||
155 |
private |
|
156 | ||
157 |
def append_options(args) |
|
158 |
if options['options'] |
|
159 |
if options['options'].is_a?(Array) |
|
160 |
args.concat(options['options']) |
|
161 |
else |
|
162 |
args.push(options['options']) |
|
163 |
end |
|
164 |
end |
|
165 |
end |
|
166 | ||
167 |
end |
|
168 | ||
169 |
end |
lib/scm_repositories_controller_patch.rb | ||
---|---|---|
258 | 258 |
repository.url = interface.access_url(path, repository) |
259 | 259 | |
260 | 260 |
if interface.local? && !interface.belongs_to_project?(name, @project.identifier) |
261 |
if(!(Repository.respond_to?(:factory_with_git_hosting) && interface == GitCreator)) |
|
261 | 262 |
flash[:warning] = l(:text_cannot_be_used_redmine_auth) |
263 |
end |
|
262 | 264 |
end |
263 | 265 |
else |
264 | 266 |
repository.errors.add(:url, :should_be_of_format_local, :repository_format => interface.repository_format) |
lib/scm_repositories_helper_patch.rb | ||
---|---|---|
16 | 16 |
end |
17 | 17 | |
18 | 18 |
module InstanceMethods |
19 | ||
19 |
|
|
20 | 20 |
def repository_field_tags_with_add(form, repository) |
21 | 21 |
reptags = repository_field_tags_without_add(form, repository) |
22 | 22 | |
... | ... | |
51 | 51 |
svntags = subversion_field_tags_without_add(form, repository) |
52 | 52 |
svntags.gsub!('<br />', '<br />') |
53 | 53 | |
54 |
if repository.new_record? && SubversionCreator.enabled? && !limit_exceeded |
|
54 |
if repository.new_record? && SubversionCreator.enabled? && !(@project.respond_to?(:repositories) && |
|
55 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
56 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i) |
|
55 | 57 |
if defined? observe_field # Rails 3.0 and below |
56 | 58 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
57 | 59 |
else # Rails 3.1 and above |
... | ... | |
84 | 86 |
def mercurial_field_tags_with_add(form, repository) |
85 | 87 |
hgtags = mercurial_field_tags_without_add(form, repository) |
86 | 88 | |
87 |
if repository.new_record? && MercurialCreator.enabled? && !limit_exceeded |
|
89 |
if repository.new_record? && MercurialCreator.enabled? && !(@project.respond_to?(:repositories) && |
|
90 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
91 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i) |
|
88 | 92 |
if defined? observe_field # Rails 3.0 and below |
89 | 93 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
90 | 94 |
else # Rails 3.1 and above |
... | ... | |
127 | 131 |
def bazaar_field_tags_with_add(form, repository) |
128 | 132 |
bzrtags = bazaar_field_tags_without_add(form, repository) |
129 | 133 | |
130 |
if repository.new_record? && BazaarCreator.enabled? && !limit_exceeded |
|
134 |
if repository.new_record? && BazaarCreator.enabled? && !(@project.respond_to?(:repositories) && |
|
135 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
136 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i) |
|
131 | 137 |
if defined? observe_field # Rails 3.0 and below |
132 | 138 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
133 | 139 |
else # Rails 3.1 and above |
... | ... | |
167 | 173 |
def git_field_tags_with_add(form, repository) |
168 | 174 |
gittags = git_field_tags_without_add(form, repository) |
169 | 175 | |
170 |
if repository.new_record? && GitCreator.enabled? && !limit_exceeded |
|
176 |
if repository.new_record? && GitCreator.enabled? && !(@project.respond_to?(:repositories) && |
|
177 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
178 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i) |
|
171 | 179 |
if defined? observe_field # Rails 3.0 and below |
172 | 180 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
173 | 181 |
else # Rails 3.1 and above |
... | ... | |
215 | 223 |
:required => true, |
216 | 224 |
:disabled => !repository.safe_attribute?('url')) |
217 | 225 | |
218 |
if repository.new_record? && GithubCreator.enabled? && !limit_exceeded |
|
226 |
if repository.new_record? && GithubCreator.enabled? && !(@project.respond_to?(:repositories) && |
|
227 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
228 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i) |
|
219 | 229 |
if defined? observe_field # Rails 3.0 and below |
220 | 230 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
221 | 231 |
else # Rails 3.1 and above |
... | ... | |
252 | 262 |
githubtags |
253 | 263 |
end |
254 | 264 | |
255 |
private |
|
265 |
|
|
256 | 266 | |
257 |
def limit_exceeded |
|
258 |
@project.respond_to?(:repositories) && |
|
259 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
260 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i |
|
261 |
end |
|
267 |
|
|
262 | 268 | |
263 | 269 |
end |
264 | 270 |
lib/scm_repositories_helper_patch.rb~ | ||
---|---|---|
1 |
require_dependency 'repositories_helper' |
|
2 | ||
3 |
module ScmRepositoriesHelperPatch |
|
4 | ||
5 |
def self.included(base) |
|
6 |
base.send(:include, InstanceMethods) |
|
7 |
base.class_eval do |
|
8 |
unloadable |
|
9 | ||
10 |
alias_method_chain :repository_field_tags, :add |
|
11 |
alias_method_chain :subversion_field_tags, :add |
|
12 |
alias_method_chain :mercurial_field_tags, :add |
|
13 |
alias_method_chain :git_field_tags, :add |
|
14 |
alias_method_chain :bazaar_field_tags, :add |
|
15 |
end |
|
16 |
end |
|
17 | ||
18 |
module InstanceMethods |
|
19 | ||
20 |
def repository_field_tags_with_add(form, repository) |
|
21 |
reptags = "" #repository_field_tags_without_add(form, repository).to_s |
|
22 | ||
23 |
button_disabled = repository.class.respond_to?(:scm_available) ? !repository.class.scm_available : false |
|
24 | ||
25 |
if ScmConfig['only_creator'] |
|
26 |
interface = SCMCreator.interface(repository) |
|
27 | ||
28 |
if interface && (interface < SCMCreator) && interface.enabled? && repository.new_record? |
|
29 |
button_disabled = true |
|
30 |
end |
|
31 |
end |
|
32 | ||
33 |
if defined? observe_field # Rails 3.0 and below |
|
34 |
if request.xhr? |
|
35 |
reptags << javascript_tag("$('repository_save')." + (button_disabled ? 'disable' : 'enable') + "();") |
|
36 |
else |
|
37 |
reptags << javascript_tag("Event.observe(window, 'load', function() { $('repository_save')." + (button_disabled ? 'disable' : 'enable') + "(); });") |
|
38 |
end |
|
39 |
else # Rails 3.1 and above |
|
40 |
if request.xhr? |
|
41 |
reptags << javascript_tag("$('#repository_save')." + (button_disabled ? "attr('disabled','disabled')" : "removeAttr('enable')") + ";") |
|
42 |
else |
|
43 |
reptags << javascript_tag("$(document).ready(function() { $('#repository_save')." + (button_disabled ? "attr('disabled','disabled')" : "removeAttr('enable')") + "; });") |
|
44 |
end |
|
45 |
end |
|
46 | ||
47 |
reptags.html_safe |
|
48 |
end |
|
49 | ||
50 |
def subversion_field_tags_with_add(form, repository) |
|
51 |
svntags = subversion_field_tags_without_add(form, repository) |
|
52 |
svntags.gsub!('<br />', '<br />') |
|
53 | ||
54 |
if repository.new_record? && SubversionCreator.enabled? && !limit_exceeded |
|
55 |
if defined? observe_field # Rails 3.0 and below |
|
56 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
|
57 |
else # Rails 3.1 and above |
|
58 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');") |
|
59 |
end |
|
60 |
svntags.sub!('<br />', ' ' + add + '<br />') |
|
61 |
svntags << hidden_field_tag(:operation, '', :id => 'repository_operation') |
|
62 |
unless request.post? |
|
63 |
path = SubversionCreator.access_root_url(SubversionCreator.default_path(@project.identifier), repository) |
|
64 |
if SubversionCreator.repository_exists?(@project.identifier) && @project.respond_to?(:repositories) |
|
65 |
path << '.' + @project.repositories.select{ |r| r.created_with_scm }.size.to_s |
|
66 |
end |
|
67 |
if defined? observe_field # Rails 3.0 and below |
|
68 |
svntags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';") |
|
69 |
else # Rails 3.1 and above |
|
70 |
svntags << javascript_tag("$('#repository_url').val('#{escape_javascript(path)}');") |
|
71 |
end |
|
72 |
end |
|
73 | ||
74 |
elsif !repository.new_record? && repository.created_with_scm && SubversionCreator.enabled? |
|
75 |
url = SubversionCreator.external_url(repository) |
|
76 |
if url |
|
77 |
svntags.sub!('(file:///, http://, https://, svn://, svn+[tunnelscheme]://)', url) |
|
78 |
end |
|
79 |
end |
|
80 | ||
81 |
svntags |
|
82 |
end |
|
83 | ||
84 |
def mercurial_field_tags_with_add(form, repository) |
|
85 |
hgtags = mercurial_field_tags_without_add(form, repository) |
|
86 | ||
87 |
if repository.new_record? && MercurialCreator.enabled? && !limit_exceeded |
|
88 |
if defined? observe_field # Rails 3.0 and below |
|
89 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
|
90 |
else # Rails 3.1 and above |
|
91 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');") |
|
92 |
end |
|
93 |
if hgtags.include?('<br />') |
|
94 |
hgtags.sub!('<br />', ' ' + add + '<br />') |
|
95 |
else |
|
96 |
hgtags.sub!('</p>', ' ' + add + '</p>') |
|
97 |
end |
|
98 |
hgtags << hidden_field_tag(:operation, '', :id => 'repository_operation') |
|
99 |
unless request.post? |
|
100 |
path = MercurialCreator.access_root_url(MercurialCreator.default_path(@project.identifier), repository) |
|
101 |
if MercurialCreator.repository_exists?(@project.identifier) && @project.respond_to?(:repositories) |
|
102 |
path << '.' + @project.repositories.select{ |r| r.created_with_scm }.size.to_s |
|
103 |
end |
|
104 |
if defined? observe_field # Rails 3.0 and below |
|
105 |
hgtags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';") |
|
106 |
else # Rails 3.1 and above |
|
107 |
hgtags << javascript_tag("$('#repository_url').val('#{escape_javascript(path)}');") |
|
108 |
end |
|
109 |
end |
|
110 | ||
111 |
elsif !repository.new_record? && repository.created_with_scm && MercurialCreator.enabled? |
|
112 |
url = MercurialCreator.external_url(repository) |
|
113 |
if url |
|
114 |
if hgtags.include?(l(:text_mercurial_repository_note)) |
|
115 |
hgtags.sub!(l(:text_mercurial_repository_note), url) |
|
116 |
elsif hgtags.include?(l(:text_mercurial_repo_example)) |
|
117 |
hgtags.sub!(l(:text_mercurial_repo_example), url) |
|
118 |
else |
|
119 |
hgtags.sub!('</p>', '<br />' + url + '</p>') |
|
120 |
end |
|
121 |
end |
|
122 |
end |
|
123 | ||
124 |
hgtags |
|
125 |
end |
|
126 | ||
127 |
def bazaar_field_tags_with_add(form, repository) |
|
128 |
bzrtags = bazaar_field_tags_without_add(form, repository) |
|
129 | ||
130 |
if repository.new_record? && BazaarCreator.enabled? && !limit_exceeded |
|
131 |
if defined? observe_field # Rails 3.0 and below |
|
132 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
|
133 |
else # Rails 3.1 and above |
|
134 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');") |
|
135 |
end |
|
136 |
bzrtags.sub!('</p>', ' ' + add + '</p>') |
|
137 |
bzrtags << hidden_field_tag(:operation, '', :id => 'repository_operation') |
|
138 |
unless request.post? |
|
139 |
path = BazaarCreator.access_root_url(BazaarCreator.default_path(@project.identifier), repository) |
|
140 |
if BazaarCreator.repository_exists?(@project.identifier) && @project.respond_to?(:repositories) |
|
141 |
path << '.' + @project.repositories.select{ |r| r.created_with_scm }.size.to_s |
|
142 |
end |
|
143 |
if defined? observe_field # Rails 3.0 and below |
|
144 |
bzrtags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';") |
|
145 |
else # Rails 3.1 and above |
|
146 |
bzrtags << javascript_tag("$('#repository_url').val('#{escape_javascript(path)}');") |
|
147 |
end |
|
148 |
if BazaarCreator.options['log_encoding'] |
|
149 |
if defined? observe_field # Rails 3.0 and below |
|
150 |
bzrtags << javascript_tag("$('repository_log_encoding').value = '#{escape_javascript(BazaarCreator.options['log_encoding'])}';") |
|
151 |
else # Rails 3.1 and above |
|
152 |
bzrtags << javascript_tag("$('#repository_log_encoding').val('#{escape_javascript(BazaarCreator.options['log_encoding'])}');") |
|
153 |
end |
|
154 |
end |
|
155 |
end |
|
156 | ||
157 |
elsif !repository.new_record? && repository.created_with_scm && BazaarCreator.enabled? |
|
158 |
url = BazaarCreator.external_url(repository) |
|
159 |
if url |
|
160 |
bzrtags.sub!('</p>', '<br />' + url + '</p>') |
|
161 |
end |
|
162 |
end |
|
163 | ||
164 |
bzrtags |
|
165 |
end |
|
166 | ||
167 |
def git_field_tags_with_add(form, repository) |
|
168 |
gittags = git_field_tags_without_add(form, repository) |
|
169 | ||
170 |
if repository.new_record? && GitCreator.enabled? && !limit_exceeded |
|
171 |
if defined? observe_field # Rails 3.0 and below |
|
172 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
|
173 |
else # Rails 3.1 and above |
|
174 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');") |
|
175 |
end |
|
176 |
if gittags.include?('<br />') |
|
177 |
gittags.sub!('<br />', ' ' + add + '<br />') |
|
178 |
else |
|
179 |
gittags.sub!('</p>', ' ' + add + '</p>') |
|
180 |
end |
|
181 |
gittags << hidden_field_tag(:operation, '', :id => 'repository_operation') |
|
182 |
unless request.post? |
|
183 |
path = GitCreator.access_root_url(GitCreator.default_path(@project.identifier), repository) |
|
184 |
if GitCreator.repository_exists?(@project.identifier) && @project.respond_to?(:repositories) |
|
185 |
offset = @project.repositories.select{ |r| r.created_with_scm }.size.to_s |
|
186 |
if path.sub!(%r{\.git$}, '.' + offset + '.git').nil? |
|
187 |
path << '.' + offset |
|
188 |
end |
|
189 |
end |
|
190 |
if defined? observe_field # Rails 3.0 and below |
|
191 |
gittags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';") |
|
192 |
else # Rails 3.1 and above |
|
193 |
gittags << javascript_tag("$('#repository_url').val('#{escape_javascript(path)}');") |
|
194 |
end |
|
195 |
end |
|
196 | ||
197 |
elsif !repository.new_record? && repository.created_with_scm && GitCreator.enabled? |
|
198 |
url = GitCreator.external_url(repository) |
|
199 |
if url |
|
200 |
if gittags.include?(l(:text_git_repository_note)) |
|
201 |
gittags.sub!(l(:text_git_repository_note), url) |
|
202 |
elsif gittags.include?(l(:text_git_repo_example)) |
|
203 |
gittags.sub!(l(:text_git_repo_example), url) |
|
204 |
else |
|
205 |
gittags.sub!('</p>', '<br />' + url + '</p>') |
|
206 |
end |
|
207 |
end |
|
208 |
end |
|
209 | ||
210 |
gittags |
|
211 |
end |
|
212 | ||
213 |
def github_field_tags(form, repository) |
|
214 |
urltag = form.text_field(:url, :size => 60, |
|
215 |
:required => true, |
|
216 |
:disabled => !repository.safe_attribute?('url')) |
|
217 | ||
218 |
if repository.new_record? && GithubCreator.enabled? && !limit_exceeded |
|
219 |
if defined? observe_field # Rails 3.0 and below |
|
220 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';") |
|
221 |
else # Rails 3.1 and above |
|
222 |
add = submit_tag(l(:button_create_new_repository), :onclick => "$('#repository_operation').val('add');") |
|
223 |
end |
|
224 |
urltag << add |
|
225 |
urltag << hidden_field_tag(:operation, '', :id => 'repository_operation') |
|
226 |
unless request.post? |
|
227 |
path = @project.identifier |
|
228 |
if defined? observe_field # Rails 3.0 and below |
|
229 |
urltag << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';") |
|
230 |
else # Rails 3.1 and above |
|
231 |
urltag << javascript_tag("$('#repository_url').val('#{escape_javascript(path)}');") |
|
232 |
end |
|
233 |
end |
|
234 |
note = l(:text_github_repository_note_new) |
|
235 |
elsif repository.new_record? |
|
236 |
note = '(https://github.com/)' |
|
237 |
end |
|
238 | ||
239 |
githubtags = content_tag('p', urltag + '<br />'.html_safe + note) |
|
240 |
githubtags << content_tag('p', form.text_field(:login, :size => 30)) + |
|
241 |
content_tag('p', form.password_field(:password, :size => 30, |
|
242 |
:name => 'ignore', |
|
243 |
:value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), |
|
244 |
:onfocus => "this.value=''; this.name='repository[password]';", |
|
245 |
:onchange => "this.name='repository[password]';") + |
|
246 |
'<br />'.html_safe + l(:text_github_credentials_note)) |
|
247 |
if !Setting.autofetch_changesets? && GithubCreator.can_register_hook? |
|
248 |
githubtags << content_tag('p', form.check_box(:extra_register_hook, :disabled => repository.extra_hook_registered) + ' ' + |
|
249 |
l(:text_github_register_hook_note)) |
|
250 |
end |
|
251 | ||
252 |
githubtags |
|
253 |
end |
|
254 | ||
255 |
private |
|
256 | ||
257 |
def limit_exceeded |
|
258 |
@project.respond_to?(:repositories) && |
|
259 |
ScmConfig['max_repos'] && ScmConfig['max_repos'].to_i > 0 && |
|
260 |
@project.repositories.select{ |r| r.created_with_scm }.size >= ScmConfig['max_repos'].to_i |
|
261 |
end |
|
262 | ||
263 |
end |
|
264 | ||
265 |
end |