##// END OF EJS Templates
Don't link multiple changesets from the same commit multiple times (#17931)....
Jean-Philippe Lang -
r13063:a56754633520
parent child
Show More
@@ -130,7 +130,7 class Changeset < ActiveRecord::Base
130 130
131 131 refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
132 132 issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
133 if issue
133 if issue && !issue_linked_to_same_commit?(issue)
134 134 referenced_issues << issue
135 135 # Don't update issues or log time when importing old commits
136 136 unless repository.created_on && committed_on && committed_on < repository.created_on
@@ -214,6 +214,12 class Changeset < ActiveRecord::Base
214 214
215 215 private
216 216
217 # Returns true if the issue is already linked to the same commit
218 # from a different repository
219 def issue_linked_to_same_commit?(issue)
220 repository.same_commits_in_scope(issue.changesets, self).any?
221 end
222
217 223 # Updates the +issue+ according to +action+
218 224 def fix_issue(issue, action)
219 225 # the issue may have been updated by the closure of another one (eg. duplicate)
@@ -442,6 +442,18 class Repository < ActiveRecord::Base
442 442 end
443 443 end
444 444
445 # Returns a scope of changesets that come from the same commit as the given changeset
446 # in different repositories that point to the same backend
447 def same_commits_in_scope(scope, changeset)
448 scope = scope.joins(:repository).where(:repositories => {:url => url, :root_url => root_url, :type => type})
449 if changeset.scmid.present?
450 scope = scope.where(:scmid => changeset.scmid)
451 else
452 scope = scope.where(:revision => changeset.revision)
453 end
454 scope
455 end
456
445 457 protected
446 458
447 459 def check_default
@@ -297,6 +297,17 class ChangesetTest < ActiveSupport::TestCase
297 297 assert_equal 0, issue.done_ratio
298 298 end
299 299
300 def test_2_repositories_with_same_backend_should_not_link_issue_multiple_times
301 Setting.commit_ref_keywords = '*'
302 r1 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn1', :url => 'file:///svn1')
303 r2 = Repository::Subversion.create!(:project_id => 1, :identifier => 'svn2', :url => 'file:///svn1')
304 now = Time.now
305 assert_difference 'Issue.find(1).changesets.count' do
306 c1 = Changeset.create!(:repository => r1, :committed_on => now, :comments => 'Fixes #1', :revision => '12345')
307 c1 = Changeset.create!(:repository => r2, :committed_on => now, :comments => 'Fixes #1', :revision => '12345')
308 end
309 end
310
300 311 def test_text_tag_revision
301 312 c = Changeset.new(:revision => '520')
302 313 assert_equal 'r520', c.text_tag
General Comments 0
You need to be logged in to leave comments. Login now