diff --git a/lib/scm_repositories_controller_patch.rb b/lib/scm_repositories_controller_patch.rb
index 6d73593..6dbe6d5 100644
--- a/lib/scm_repositories_controller_patch.rb
+++ b/lib/scm_repositories_controller_patch.rb
@@ -8,7 +8,8 @@ module ScmRepositoriesControllerPatch
base.class_eval do
unloadable
before_filter :delete_scm, :only => :destroy
- alias_method :edit, :edit_with_add
+ alias_method :create, :create_with_add
+ alias_method_chain :edit, :add
end
end
@@ -24,6 +25,87 @@ module ScmRepositoriesControllerPatch
end
end
+ def create_repository (params)
+ if @repository.valid? && params[:operation].present? && params[:operation] == 'add'
+ attributes = params[:repository]
+ attrs = {}
+ extra = {}
+ attributes.each do |name, value|
+ if name =~ %r{^extra_}
+ extra[name] = value
+ else
+ attrs[name] = value
+ end
+ end
+
+ if attrs
+
+ begin
+ interface = Object.const_get("#{params[:repository_scm]}Creator")
+
+ name = interface.repository_name(attrs['url'])
+ if name
+ path = interface.path(name)
+ if File.directory?(path)
+ @repository.errors.add(:url, :already_exists)
+ else
+ RAILS_DEFAULT_LOGGER.info "Creating reporitory: #{path}"
+ interface.execute(ScmConfig['pre_create'], path, @project) if ScmConfig['pre_create']
+ if interface.create_repository(path)
+ interface.execute(ScmConfig['post_create'], path, @project) if ScmConfig['post_create']
+ @repository.created_with_scm = true
+ unless interface.copy_hooks(path)
+ RAILS_DEFAULT_LOGGER.warn "Hooks copy failed"
+ end
+ else
+ RAILS_DEFAULT_LOGGER.error "Repository creation failed"
+ end
+ end
+
+ @repository.root_url = interface.access_root_url(path)
+ @repository.url = interface.access_url(path)
+
+ if !interface.repository_name_equal?(name, @project.identifier)
+ flash[:warning] = l(:text_cannot_be_used_redmine_auth)
+ end
+ else
+ @repository.errors.add(:url, :should_be_of_format_local, :format => interface.repository_format)
+ end
+
+ rescue NameError
+ RAILS_DEFAULT_LOGGER.error "Can't find interface for #{params[:repository_scm]}."
+ @repository.errors.add_to_base(:scm_not_supported)
+ end
+ end
+ end
+
+ end
+
+ #def create
+ # @repository = Repository.factory(params[:repository_scm], params[:repository])
+ # @repository.project = @project
+ # if request.post? && @repository.save
+ # redirect_to settings_project_path(@project, :tab => 'repositories')
+ # else
+ # render :action => 'new'
+ # end
+ #end
+
+ def create_with_add
+ @repository = Repository.factory(params[:repository_scm], params[:repository])
+ @repository.project = @project
+ if request.post?
+
+ create_repository(params)
+
+ if @repository.save
+ redirect_to settings_project_path(@project, :tab => 'repositories')
+ end
+ else
+ render :action => 'new'
+ end
+ end
+
# Original function
#def edit
# @repository = @project.repository
@@ -56,8 +138,12 @@ module ScmRepositoriesControllerPatch
#end
def edit_with_add
+ if @project.respond_to?('repositories')
+ edit_without_add()
+ return
+ end
@repository = @project.repository
- if !@repository && !params[:repository_scm].blank?
+ if (!@repository || @project.respond_to?('repositories')) && !params[:repository_scm].blank?
@repository = Repository.factory(params[:repository_scm])
@repository.project = @project if @repository
end
@@ -74,48 +160,8 @@ module ScmRepositoriesControllerPatch
end
end
@repository.attributes = attrs
-
- if @repository.valid? && params[:operation].present? && params[:operation] == 'add'
- if attrs
-
- begin
- interface = Object.const_get("#{params[:repository_scm]}Creator")
-
- name = interface.repository_name(attrs['url'])
- if name
- path = interface.path(name)
- if File.directory?(path)
- @repository.errors.add(:url, :already_exists)
- else
- RAILS_DEFAULT_LOGGER.info "Creating reporitory: #{path}"
- interface.execute(ScmConfig['pre_create'], path, @project) if ScmConfig['pre_create']
- if interface.create_repository(path)
- interface.execute(ScmConfig['post_create'], path, @project) if ScmConfig['post_create']
- @repository.created_with_scm = true
- unless interface.copy_hooks(path)
- RAILS_DEFAULT_LOGGER.warn "Hooks copy failed"
- end
- else
- RAILS_DEFAULT_LOGGER.error "Repository creation failed"
- end
- end
-
- @repository.root_url = interface.access_root_url(path)
- @repository.url = interface.access_url(path)
-
- if !interface.repository_name_equal?(name, @project.identifier)
- flash[:warning] = l(:text_cannot_be_used_redmine_auth)
- end
- else
- @repository.errors.add(:url, :should_be_of_format_local, :format => interface.repository_format)
- end
-
- rescue NameError
- RAILS_DEFAULT_LOGGER.error "Can't find interface for #{params[:repository_scm]}."
- @repository.errors.add_to_base(:scm_not_supported)
- end
- end
- end
+
+ create_repository(params)
if @repository.errors.empty?
@repository.merge_extra_info(extra) if @repository.respond_to?(:merge_extra_info)
@@ -125,7 +171,7 @@ module ScmRepositoriesControllerPatch
render(:update) do |page|
page.replace_html("tab-content-repository", :partial => 'projects/settings/repository')
- if @repository && !@project.repository
+ if @repository && (!@project.repository||@repository.respond_to?('identifier') && (@repository.identifier == nil))
@project.reload
page.replace_html("main-menu", render_main_menu(@project))
end
diff --git a/lib/scm_repositories_helper_patch.rb b/lib/scm_repositories_helper_patch.rb
index 9742445..aac8254 100644
--- a/lib/scm_repositories_helper_patch.rb
+++ b/lib/scm_repositories_helper_patch.rb
@@ -22,12 +22,15 @@ module ScmRepositoriesHelperPatch
def subversion_field_tags_with_add(form, repository)
svntags = subversion_field_tags_without_add(form, repository)
- if !@project.repository && SubversionCreator.enabled?
+ if (!@project.repository || repository.respond_to?('identifier') && (repository.identifier == nil) ) && SubversionCreator.enabled?
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';")
svntags['
'] = ' ' + add + '
'
svntags << hidden_field_tag(:operation, '', :id => 'repository_operation')
unless request.post?
path = SubversionCreator.access_root_url(SubversionCreator.default_path(@project.identifier))
+ if @project.repository
+ path << '.subrepo' + @project.repositories.size.to_s
+ end
svntags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';")
end
@@ -45,7 +48,7 @@ module ScmRepositoriesHelperPatch
def mercurial_field_tags_with_add(form, repository)
hgtags = mercurial_field_tags_without_add(form, repository)
- if !@project.repository && MercurialCreator.enabled?
+ if (!@project.repository || repository.respond_to?('identifier') && (repository.identifier == nil) ) && MercurialCreator.enabled?
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';")
if hgtags.include?('
')
hgtags['
'] = ' ' + add + '
'
@@ -55,6 +58,9 @@ module ScmRepositoriesHelperPatch
hgtags << hidden_field_tag(:operation, '', :id => 'repository_operation')
unless request.post?
path = MercurialCreator.access_root_url(MercurialCreator.default_path(@project.identifier))
+ if @project.repository
+ path << '.subrepo' + @project.repositories.size.to_s
+ end
hgtags << javascript_tag("$('repository_url').value = '#{escape_javascript(path)}';")
end
@@ -78,12 +84,15 @@ module ScmRepositoriesHelperPatch
def bazaar_field_tags_with_add(form, repository)
bzrtags = bazaar_field_tags_without_add(form, repository)
- if !@project.repository && BazaarCreator.enabled?
+ if (!@project.repository || repository.respond_to?('identifier') && (repository.identifier == nil) ) && BazaarCreator.enabled?
add = submit_tag(l(:button_create_new_repository), :onclick => "$('repository_operation').value = 'add';")
bzrtags['