From c8e97381f7a3f18367629e3b172178f165849aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 10:19:16 +0100 Subject: [PATCH 1/7] implemented patch http://www.redmine.org/attachments/4735/0001-.patch not fully working yet --- app/controllers/repositories_controller.rb | 22 +++++++++------ app/helpers/application_helper.rb | 5 ++- app/helpers/repositories_helper.rb | 4 +- app/models/changeset.rb | 7 +++++ app/models/project.rb | 2 +- app/views/projects/settings/_repository.rhtml | 32 +++++++++++++++++------ app/views/repositories/_dir_list_content.rhtml | 6 ++-- app/views/repositories/show.rhtml | 6 ++++ lib/redmine.rb | 2 +- 9 files changed, 59 insertions(+), 27 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 6195c64..9b44852 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -36,17 +36,19 @@ class RepositoriesController < ApplicationController def edit @repository = @project.repository - if !@repository - @repository = Repository.factory(params[:repository_scm]) - @repository.project = @project if @repository + rid = params[:rid] ? params[:rid].to_i : 0 + + if !@repository[rid] + @repository[rid] = Repository.factory(params[:repository_scm]) + @repository[rid].project = @project if @repository[rid] end - if request.post? && @repository - @repository.attributes = params[:repository] - @repository.save + if request.post? && @repository[rid] + @repository[rid].attributes = params[:repository] + @repository[rid].save end render(:update) do |page| page.replace_html "tab-content-repository", :partial => 'projects/settings/repository' - if @repository && !@project.repository + if @repository[rid] && !@project.repository @project.reload #needed to reload association page.replace_html "main-menu", render_main_menu(@project) end @@ -139,7 +141,8 @@ class RepositoriesController < ApplicationController end def revision - @changeset = @repository.find_changeset_by_name(@rev) + rid = params[:rid] ? params[:rid].to_i : 0 + @changeset = @repository[rid].find_changeset_by_name(@rev) raise ChangesetNotFound unless @changeset respond_to do |format| @@ -205,7 +208,8 @@ class RepositoriesController < ApplicationController def find_repository @project = Project.find(params[:id]) - @repository = @project.repository + rid = params[:rid] ? params[:rid].to_i : 0 + @repository = @project.repository[rid] (render_404; return false) unless @repository @path = params[:path].join('/') unless params[:path].nil? @path ||= '' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 3cdd3ad..f771d5b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -106,8 +106,9 @@ module ApplicationHelper text = options.delete(:text) || format_revision(revision) rev = revision.respond_to?(:identifier) ? revision.identifier : revision - link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev}, - :title => l(:label_revision_id, format_revision(revision))) + link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision, :rid => params[:rid]}, :title => l(:label_revision_id, revision)) + # link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev}, + # :title => l(:label_revision_id, format_revision(revision))) end # Generates a link to a project if active diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 63ea522..0788ac3 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -140,7 +140,7 @@ module RepositoriesHelper send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' end - def scm_select_tag(repository) + def scm_select_tag(repository, rid) scm_options = [["--- #{l(:actionview_instancetag_blank_option)} ---", '']] Redmine::Scm::Base.all.each do |scm| scm_options << ["Repository::#{scm}".constantize.scm_name, scm] if Setting.enabled_scm.include?(scm) || (repository && repository.class.name.demodulize == scm) @@ -149,7 +149,7 @@ module RepositoriesHelper select_tag('repository_scm', options_for_select(scm_options, repository.class.name.demodulize), :disabled => (repository && !repository.new_record?), - :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project }, :method => :get, :with => "Form.serialize(this.form)") + :onchange => remote_function(:url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid }, :method => :get, :with => "Form.serialize(this.form)") ) end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e49113e..fb27c4c 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -160,6 +160,13 @@ class Changeset < ActiveRecord::Base def next @next ||= Changeset.find(:first, :conditions => ['id > ? AND repository_id = ?', self.id, self.repository_id], :order => 'id ASC') end + + def rid + project.repository.each_with_index do |r, i| + return i if r.id == repository.id + end + -1 + end # Strips and reencodes a commit log before insertion into the database def self.normalize_comments(str) diff --git a/app/models/project.rb b/app/models/project.rb index 891db8b..806c68f 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -46,7 +46,7 @@ class Project < ActiveRecord::Base has_many :news, :dependent => :delete_all, :include => :author has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" has_many :boards, :dependent => :destroy, :order => "position ASC" - has_one :repository, :dependent => :destroy + has_many :repository, :dependent => :destroy has_many :changesets, :through => :repository has_one :wiki, :dependent => :destroy # Custom field for the project issues diff --git a/app/views/projects/settings/_repository.rhtml b/app/views/projects/settings/_repository.rhtml index 18bb2cd..e8d99e0 100644 --- a/app/views/projects/settings/_repository.rhtml +++ b/app/views/projects/settings/_repository.rhtml @@ -1,24 +1,38 @@ -<% remote_form_for :repository, @repository, - :url => { :controller => 'repositories', :action => 'edit', :id => @project }, +<% @repository.each_with_index do |r, rid| %> +<% remote_form_for :repository, r, + :url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid }, :builder => TabularFormBuilder, :lang => current_language do |f| %> -<%= error_messages_for 'repository' %> +<%= error_messages_for 'r' %>
-

<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository) %>

-<%= repository_field_tags(f, @repository) if @repository %> +

<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(r, rid) %>

+<%= repository_field_tags(f, r) if r %>
-<% if @repository && !@repository.new_record? %> -<%= link_to(l(:label_user_plural), {:controller => 'repositories', :action => 'committers', :id => @project}, :class => 'icon icon-user') %> -<%= link_to(l(:button_delete), {:controller => 'repositories', :action => 'destroy', :id => @project}, +<% if @repository[0] && !r.new_record? %> +<%= link_to(l(:label_user_plural), {:controller => 'repositories', :action => 'committers', :id => @project, :rid => rid}, :class => 'icon icon-user') %> +<%= link_to(l(:button_delete), {:controller => 'repositories', :action => 'destroy', :id => @project, :rid => rid }, :confirm => l(:text_are_you_sure), :method => :post, :class => 'icon icon-del') %> <% end %>
-<%= submit_tag((@repository.nil? || @repository.new_record?) ? l(:button_create) : l(:button_save), :disabled => @repository.nil?) %> +<%= submit_tag((r.nil? || r.new_record?) ? l(:button_create) : l(:button_save), :disabled => r.nil?) %> <% end %> +<% end %> + +<% rid = @repository.size + remote_form_for :repository, @repository[rid], + :url => { :controller => 'repositories', :action => 'edit', :id => @project, :rid => rid }, + :builder => TabularFormBuilder, + :lang => current_language do |f| %> +
+

<%= label_tag('repository_scm', l(:label_scm)) %><%= scm_select_tag(@repository[rid], rid) %>

+<%= repository_field_tags(f, @repository[rid]) if @repository[rid] %> +
+<%= submit_tag((@repository[rid].nil? || @repository[rid].new_record?) ? l(:button_create) : l(:button_save), :disabled => @repository[rid].nil?) %> +<% end %> \ No newline at end of file diff --git a/app/views/repositories/_dir_list_content.rhtml b/app/views/repositories/_dir_list_content.rhtml index 66574f1..5bc5960 100644 --- a/app/views/repositories/_dir_list_content.rhtml +++ b/app/views/repositories/_dir_list_content.rhtml @@ -4,7 +4,7 @@ <% if entry.is_dir? %> -">  <% end %> <%= link_to h(entry.name), - {:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev}, + {:action => (entry.is_dir? ? 'show' : 'changes'), :id => @project, :path => to_path_param(entry.path), :rev => @rev, :rid => params[:rid]}, :class => (entry.is_dir? ? 'icon icon-folder' : "icon icon-file #{Redmine::MimeType.css_class_of(entry.name)}")%> <%= (entry.size ? number_to_human_size(entry.size) : "?") unless entry.is_dir? %> -<% changeset = @project.repository.changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> +<% changeset = @project.repository[params[:rid].to_i].changesets.find_by_revision(entry.lastrev.identifier) if entry.lastrev && entry.lastrev.identifier %> <%= link_to_revision(changeset, @project) if changeset %> <%= distance_of_time_in_words(entry.lastrev.time, Time.now) if entry.lastrev && entry.lastrev.time %> <%= changeset.nil? ? h(entry.lastrev.author.to_s.split('<').first) : changeset.author if entry.lastrev %> diff --git a/app/views/repositories/show.rhtml b/app/views/repositories/show.rhtml index 35106fe..0bab5ac 100644 --- a/app/views/repositories/show.rhtml +++ b/app/views/repositories/show.rhtml @@ -4,6 +4,12 @@ <%= render :partial => 'navigation' %> + +

<%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %>

<% if !@entries.nil? && authorize_for('repositories', 'browse') %> diff --git a/lib/redmine.rb b/lib/redmine.rb index 7fcd764..1f3c66d 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -201,7 +201,7 @@ Redmine::MenuManager.map :project_menu do |menu| :if => Proc.new { |p| p.boards.any? }, :caption => :label_board_plural menu.push :files, { :controller => 'files', :action => 'index' }, :caption => :label_file_plural, :param => :project_id menu.push :repository, { :controller => 'repositories', :action => 'show' }, - :if => Proc.new { |p| p.repository && !p.repository.new_record? } + :if => Proc.new { |p| !p.repository.empty? && !p.repository[0].new_record? } menu.push :settings, { :controller => 'projects', :action => 'settings' }, :last => true end -- 1.7.3.4 From f002814cf3a9216dd166a3226191c85c523f8bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 12:08:57 +0100 Subject: [PATCH 2/7] implemented names for repositories --- app/controllers/repositories_controller.rb | 5 ++--- app/controllers/sys_controller.rb | 6 ++++-- app/helpers/application_helper.rb | 5 +---- app/helpers/repositories_helper.rb | 12 +++++++++++- app/views/issues/_changesets.rhtml | 2 +- app/views/repositories/_breadcrumbs.rhtml | 10 ++++++---- app/views/repositories/_navigation.rhtml | 2 ++ app/views/repositories/show.rhtml | 2 +- db/migrate/109_add_name_to_repository.rb | 9 +++++++++ 9 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 db/migrate/109_add_name_to_repository.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9b44852..3f172a6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -140,9 +140,8 @@ class RepositoriesController < ApplicationController (render_error l(:error_scm_annotate); return) if @annotate.nil? || @annotate.empty? end - def revision - rid = params[:rid] ? params[:rid].to_i : 0 - @changeset = @repository[rid].find_changeset_by_name(@rev) + def revision + @changeset = @repository.find_changeset_by_name(@rev) raise ChangesetNotFound unless @changeset respond_to do |format| diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb index be88eb2..40594d3 100644 --- a/app/controllers/sys_controller.rb +++ b/app/controllers/sys_controller.rb @@ -46,8 +46,10 @@ class SysController < ActionController::Base projects = Project.active.has_module(:repository).find(:all, :include => :repository) end projects.each do |project| - if project.repository - project.repository.fetch_changesets + if project.repository.length > 0 + project.repository.each do |repo| + repo.fetch_changesets + end end end render :nothing => true, :status => 200 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f771d5b..c1303c8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -105,10 +105,7 @@ module ApplicationHelper def link_to_revision(revision, project, options={}) text = options.delete(:text) || format_revision(revision) rev = revision.respond_to?(:identifier) ? revision.identifier : revision - - link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision, :rid => params[:rid]}, :title => l(:label_revision_id, revision)) - # link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => rev}, - # :title => l(:label_revision_id, format_revision(revision))) + link_to(text, {:controller => 'repositories', :action => 'revision', :id => project, :rev => revision, :rid => params[:rid]}, :title => l(:label_revision_id, format_revision(revision))) end # Generates a link to a project if active diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 0788ac3..31dc22a 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -137,7 +137,9 @@ module RepositoriesHelper def repository_field_tags(form, repository) method = repository.class.name.demodulize.underscore + "_field_tags" - send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' + namefield = repositoryname_field_tag(form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' + html = send(method, form, repository) if repository.is_a?(Repository) && respond_to?(method) && method != 'repository_field_tags' + return namefield + html end def scm_select_tag(repository, rid) @@ -195,4 +197,12 @@ module RepositoriesHelper def filesystem_field_tags(form, repository) content_tag('p', form.text_field(:url, :label => 'Root directory', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) end + + def repositoryname_field_tag(form, repository) + content_tag('p', form.text_field(:name, :label => 'Name', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) + end + + def link_to_repository(repository, rid) + link_to !repository.name.empty? ? repository.name : repository.url, :rid => rid + end end diff --git a/app/views/issues/_changesets.rhtml b/app/views/issues/_changesets.rhtml index 52cd60f..aa04216 100644 --- a/app/views/issues/_changesets.rhtml +++ b/app/views/issues/_changesets.rhtml @@ -1,7 +1,7 @@ <% changesets.each do |changeset| %>

<%= link_to("#{l(:label_revision)} #{changeset.revision}", - :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision) %>
+ :controller => 'repositories', :action => 'revision', :id => changeset.project, :rev => changeset.revision, :rid => changeset.rid) %>
<%= authoring(changeset.committed_on, changeset.author) %>

<%= textilizable(changeset, :comments) %> diff --git a/app/views/repositories/_breadcrumbs.rhtml b/app/views/repositories/_breadcrumbs.rhtml index bab0ff3..a484fae 100644 --- a/app/views/repositories/_breadcrumbs.rhtml +++ b/app/views/repositories/_breadcrumbs.rhtml @@ -1,5 +1,7 @@ -<%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev %> -<% +<% if params[:rid] %> +(<%= @project.repository[params[:rid].to_i].url %>) +<% end %> +<%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev , :rid => params[:rid]%><% dirs = path.split('/') if 'file' == kind filename = dirs.pop @@ -10,10 +12,10 @@ dirs.each do |dir| link_path << '/' unless link_path.empty? link_path << "#{dir}" %> - / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev %> + / <%= link_to h(dir), :action => 'show', :id => @project, :path => to_path_param(link_path), :rev => @rev, :rid => params[:rid] %> <% end %> <% if filename %> - / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev %> + / <%= link_to h(filename), :action => 'changes', :id => @project, :path => to_path_param("#{link_path}/#{filename}"), :rev => @rev, :rid => params[:rid] %> <% end %> <%= "@ #{h revision}" if revision %> diff --git a/app/views/repositories/_navigation.rhtml b/app/views/repositories/_navigation.rhtml index 5671e29..247aa37 100644 --- a/app/views/repositories/_navigation.rhtml +++ b/app/views/repositories/_navigation.rhtml @@ -16,6 +16,8 @@ <%= select_tag :tag, options_for_select([''] + @repository.tags,@rev), :id => 'tag' %> <% end -%> + <%= hidden_field_tag :rid, params[:rid] %> + | <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 8 %> <% end -%> diff --git a/app/views/repositories/show.rhtml b/app/views/repositories/show.rhtml index 0bab5ac..d1eff9d 100644 --- a/app/views/repositories/show.rhtml +++ b/app/views/repositories/show.rhtml @@ -6,7 +6,7 @@
    <% @project.repository.each_with_index do |r, i| %> -
  • <%= link_to r.url, :rid => i %>
  • +
  • <%= link_to_repository(r,i) %>
  • <% end %>
diff --git a/db/migrate/109_add_name_to_repository.rb b/db/migrate/109_add_name_to_repository.rb new file mode 100644 index 0000000..5703d4b --- /dev/null +++ b/db/migrate/109_add_name_to_repository.rb @@ -0,0 +1,9 @@ +class AddNameToRepository < ActiveRecord::Migration + def self.up + add_column :repositories, :name, :string, :null => false, :default => "" + end + + def self.down + remove_column :repositories, :name + end +end -- 1.7.3.4 From 92317604a186b5eae4defeaaf594dbf5523755ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 12:20:05 +0100 Subject: [PATCH 3/7] refactored display of repo name --- app/helpers/repositories_helper.rb | 4 ---- app/models/repository.rb | 4 ++++ app/views/repositories/_breadcrumbs.rhtml | 2 +- app/views/repositories/show.rhtml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 31dc22a..b2ff75c 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -201,8 +201,4 @@ module RepositoriesHelper def repositoryname_field_tag(form, repository) content_tag('p', form.text_field(:name, :label => 'Name', :size => 60, :required => true, :disabled => (repository && !repository.root_url.blank?))) end - - def link_to_repository(repository, rid) - link_to !repository.name.empty? ? repository.name : repository.url, :rid => rid - end end diff --git a/app/models/repository.rb b/app/models/repository.rb index dee705c..f24f256 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -32,6 +32,10 @@ class Repository < ActiveRecord::Base write_attribute(:url, arg ? arg.to_s.strip : nil) end + def display_name + self.name.empty? ? self.url : self.name + end + # Removes leading and trailing whitespace def root_url=(arg) write_attribute(:root_url, arg ? arg.to_s.strip : nil) diff --git a/app/views/repositories/_breadcrumbs.rhtml b/app/views/repositories/_breadcrumbs.rhtml index a484fae..c9ecaa5 100644 --- a/app/views/repositories/_breadcrumbs.rhtml +++ b/app/views/repositories/_breadcrumbs.rhtml @@ -1,5 +1,5 @@ <% if params[:rid] %> -(<%= @project.repository[params[:rid].to_i].url %>) +(<%= @project.repository[params[:rid].to_i].display_name %>) <% end %> <%= link_to 'root', :action => 'show', :id => @project, :path => '', :rev => @rev , :rid => params[:rid]%><% dirs = path.split('/') diff --git a/app/views/repositories/show.rhtml b/app/views/repositories/show.rhtml index d1eff9d..2290b77 100644 --- a/app/views/repositories/show.rhtml +++ b/app/views/repositories/show.rhtml @@ -6,7 +6,7 @@
    <% @project.repository.each_with_index do |r, i| %> -
  • <%= link_to_repository(r,i) %>
  • +
  • <%= link_to r.display_name, :rid => i %>
  • <% end %>
-- 1.7.3.4 From 14236b90c682a72c4f8feaabf5eb6fbd50d83342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 15:44:34 +0100 Subject: [PATCH 4/7] refactored changeset_test refs #779 --- test/unit/changeset_test.rb | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/test/unit/changeset_test.rb b/test/unit/changeset_test.rb index 2f0415d..f1f9e71 100644 --- a/test/unit/changeset_test.rb +++ b/test/unit/changeset_test.rb @@ -32,7 +32,7 @@ class ChangesetTest < ActiveSupport::TestCase Setting.commit_ref_keywords = '*' Setting.commit_fix_keywords = 'fixes , closes' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => 'New commit (#2). Fixes #1') c.scan_comment_for_issue_ids @@ -48,7 +48,7 @@ class ChangesetTest < ActiveSupport::TestCase Setting.commit_ref_keywords = 'refs' Setting.commit_fix_keywords = '' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => 'Ignores #2. Refs #1') c.scan_comment_for_issue_ids @@ -60,7 +60,7 @@ class ChangesetTest < ActiveSupport::TestCase Setting.commit_ref_keywords = '*' Setting.commit_fix_keywords = '' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => 'Ignores #2. Refs #1') c.scan_comment_for_issue_ids @@ -72,7 +72,7 @@ class ChangesetTest < ActiveSupport::TestCase Setting.commit_ref_keywords = '*' Setting.commit_logtime_enabled = '1' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => 24.hours.ago, :comments => 'Worked on this issue #1 @2h', :revision => '520', @@ -98,7 +98,7 @@ class ChangesetTest < ActiveSupport::TestCase Setting.commit_fix_keywords = 'fixes , closes' Setting.commit_logtime_enabled = '1' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => 'This is a comment. Fixes #1 @2.5, #2 @1', :user => User.find(2)) @@ -117,7 +117,7 @@ class ChangesetTest < ActiveSupport::TestCase def test_ref_keywords_any_line_start Setting.commit_ref_keywords = '*' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => '#1 is the reason of this commit') c.scan_comment_for_issue_ids @@ -128,7 +128,7 @@ class ChangesetTest < ActiveSupport::TestCase def test_ref_keywords_allow_brackets_around_a_issue_number Setting.commit_ref_keywords = '*' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => '[#1] Worked on this issue') c.scan_comment_for_issue_ids @@ -139,7 +139,7 @@ class ChangesetTest < ActiveSupport::TestCase def test_ref_keywords_allow_brackets_around_multiple_issue_numbers Setting.commit_ref_keywords = '*' - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => '[#1 #2, #3] Worked on these') c.scan_comment_for_issue_ids @@ -148,7 +148,7 @@ class ChangesetTest < ActiveSupport::TestCase end def test_commit_referencing_a_subproject_issue - c = Changeset.new(:repository => Project.find(1).repository, + c = Changeset.new(:repository => Project.find(1).repository.first, :committed_on => Time.now, :comments => 'refs #5, a subproject issue') c.scan_comment_for_issue_ids -- 1.7.3.4 From 7f99f3ab9a3d50002a2e0ace0666236367df8205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 16:13:15 +0100 Subject: [PATCH 5/7] refactored create_project_repository to respect multiple repos --- app/controllers/sys_controller.rb | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/app/controllers/sys_controller.rb b/app/controllers/sys_controller.rb index 40594d3..0ff8d93 100644 --- a/app/controllers/sys_controller.rb +++ b/app/controllers/sys_controller.rb @@ -24,17 +24,15 @@ class SysController < ActionController::Base end def create_project_repository + project = Project.find(params[:id]) - if project.repository - render :nothing => true, :status => 409 + + logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}." + project.repository.push(Repository.factory(params[:vendor], params[:repository])) + if project.repository.last.save + render :xml => project.repository.last, :status => 201 else - logger.info "Repository for #{project.name} was reported to be created by #{request.remote_ip}." - project.repository = Repository.factory(params[:vendor], params[:repository]) - if project.repository && project.repository.save - render :xml => project.repository, :status => 201 - else - render :nothing => true, :status => 422 - end + render :nothing => true, :status => 422 end end -- 1.7.3.4 From 380244e104d6d62426012fe1316405495c4e6bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Thu, 6 Jan 2011 16:13:31 +0100 Subject: [PATCH 6/7] updated tests --- test/functional/repositories_controller_test.rb | 4 ++-- .../functional/repositories_cvs_controller_test.rb | 4 ++-- test/functional/sys_controller_test.rb | 10 +++++++--- test/unit/project_test.rb | 2 +- test/unit/repository_test.rb | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/functional/repositories_controller_test.rb b/test/functional/repositories_controller_test.rb index 629be69..d809d61 100644 --- a/test/functional/repositories_controller_test.rb +++ b/test/functional/repositories_controller_test.rb @@ -72,7 +72,7 @@ class RepositoriesControllerTest < ActionController::TestCase def test_committers @request.session[:user_id] = 2 # add a commit with an unknown user - Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') + Changeset.create!(:repository => Project.find(1).repository.first, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') get :committers, :id => 1 assert_response :success @@ -94,7 +94,7 @@ class RepositoriesControllerTest < ActionController::TestCase def test_map_committers @request.session[:user_id] = 2 # add a commit with an unknown user - c = Changeset.create!(:repository => Project.find(1).repository, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') + c = Changeset.create!(:repository => Project.find(1).repository.first, :committer => 'foo', :committed_on => Time.now, :revision => 100, :comments => 'Committed by foo.') assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do post :committers, :id => 1, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']} diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb index 58b44ec..eaf7bc8 100644 --- a/test/functional/repositories_cvs_controller_test.rb +++ b/test/functional/repositories_cvs_controller_test.rb @@ -38,8 +38,8 @@ class RepositoriesCvsControllerTest < ActionController::TestCase User.current = nil @project = Project.find(1) - @project.repository = Repository::Cvs.create(:root_url => REPOSITORY_PATH, - :url => MODULE_NAME) + @project.repository.push(Repository::Cvs.create(:root_url => REPOSITORY_PATH, + :url => MODULE_NAME)) end if File.directory?(REPOSITORY_PATH) diff --git a/test/functional/sys_controller_test.rb b/test/functional/sys_controller_test.rb index 6a3da29..13cda3a 100644 --- a/test/functional/sys_controller_test.rb +++ b/test/functional/sys_controller_test.rb @@ -42,14 +42,18 @@ class SysControllerTest < ActionController::TestCase end def test_create_project_repository - assert_nil Project.find(4).repository + assert_nil Project.find(4).repository.first post :create_project_repository, :id => 4, :vendor => 'Subversion', - :repository => { :url => 'file:///create/project/repository/subproject2'} + :repository => { + :url => 'file:///create/project/repository/subproject2', + :name => 'Test Subversion Repository' } + + assert_response :created - r = Project.find(4).repository + r = Project.find(4).repository.first assert r.is_a?(Repository::Subversion) assert_equal 'file:///create/project/repository/subproject2', r.url end diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index 8eb79fd..08c583e 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -48,7 +48,7 @@ class ProjectTest < ActiveSupport::TestCase should_have_many :boards should_have_many :changesets, :through => :repository - should_have_one :repository + should_have_many :repository should_have_one :wiki should_have_and_belong_to_many :trackers diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 252230b..aa0cf9a 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -35,7 +35,7 @@ class RepositoryTest < ActiveSupport::TestCase :enumerations def setup - @repository = Project.find(1).repository + @repository = Project.find(1).repository.first end def test_create -- 1.7.3.4 From 0ed9c9b0427da5738428d55166ba5929e477d3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Gr=C3=BCndler?= Date: Sun, 9 Jan 2011 12:36:24 +0100 Subject: [PATCH 7/7] added link to repository in revision view --- app/views/repositories/revision.rhtml | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/app/views/repositories/revision.rhtml b/app/views/repositories/revision.rhtml index 483e358..9c61a22 100644 --- a/app/views/repositories/revision.rhtml +++ b/app/views/repositories/revision.rhtml @@ -19,6 +19,7 @@ <% end %>
+

<%= link_to(@changeset.repository.display_name, :controller => 'repositories', :rid => @changeset.rid, :action => 'show') %>


<%= l(:label_revision) %> <%= format_revision(@changeset) %>

<% if @changeset.scmid %>ID: <%= @changeset.scmid %>
<% end %> -- 1.7.3.4