]> source.dussan.org Git - redmine.git/commitdiff
Don't update issues nor log time when importing old changesets (#4823).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 5 Oct 2013 10:33:03 +0000 (10:33 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 5 Oct 2013 10:33:03 +0000 (10:33 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12199 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/changeset.rb
db/migrate/20131005100610_add_repositories_created_on.rb [new file with mode: 0644]
test/fixtures/repositories.yml
test/unit/changeset_test.rb

index 87fdaffcd1a9762578b0b0ced7086cb0edb5f14b..2c574f75e14aa446a1e104cce032dfa9a40ac5a4 100644 (file)
@@ -132,8 +132,11 @@ class Changeset < ActiveRecord::Base
         issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
         if issue
           referenced_issues << issue
-          fix_issue(issue, action) if fix_keywords.include?(action)
-          log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
+          # Don't update issues or log time when importing old commits
+          unless repository.created_on && committed_on && committed_on < repository.created_on
+            fix_issue(issue, action) if fix_keywords.include?(action)
+            log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
+          end
         end
       end
     end
diff --git a/db/migrate/20131005100610_add_repositories_created_on.rb b/db/migrate/20131005100610_add_repositories_created_on.rb
new file mode 100644 (file)
index 0000000..1f98221
--- /dev/null
@@ -0,0 +1,9 @@
+class AddRepositoriesCreatedOn < ActiveRecord::Migration
+  def up
+    add_column :repositories, :created_on, :timestamp
+  end
+
+  def down
+    remove_column :repositories, :created_on
+  end
+end
index 5be709a1d0780ec6c8fb2df81fe551ea53169bab..20225bb220bd95f9a0991beb6356f95f7645f166 100644 (file)
@@ -8,6 +8,7 @@ repositories_001:
   login: ""
   type: Repository::Subversion
   is_default: true
+  created_on: 2006-07-19 19:04:21 +02:00
 repositories_002: 
   project_id: 2
   url: svn://localhost/test
@@ -17,3 +18,4 @@ repositories_002:
   login: ""
   type: Repository::Subversion
   is_default: true
+  created_on: 2006-07-19 19:04:21 +02:00
index 3ead6b8436dd126105f4f551a28ac22b93afeff4..93bd7bba51802ef3e168a6387c56f458928a527c 100644 (file)
@@ -254,6 +254,28 @@ class ChangesetTest < ActiveSupport::TestCase
     end
   end
 
+  def test_old_commits_should_not_update_issues_nor_log_time
+    Setting.commit_ref_keywords = '*'
+    Setting.commit_update_keywords = {'fixes , closes' => {'status_id' => '5', 'done_ratio' => '90'}}
+    Setting.commit_logtime_enabled = '1'
+
+    repository = Project.find(1).repository
+    repository.created_on = Time.now
+    repository.save!
+
+    c = Changeset.new(:repository   => repository,
+                      :committed_on => 1.month.ago,
+                      :comments     => 'New commit (#2). Fixes #1 @1h',
+                      :revision     => '12345')
+    assert_no_difference 'TimeEntry.count' do
+      assert c.save
+    end
+    assert_equal [1, 2], c.issue_ids.sort
+    issue = Issue.find(1)
+    assert_equal 1, issue.status_id
+    assert_equal 0, issue.done_ratio
+  end
+
   def test_text_tag_revision
     c = Changeset.new(:revision => '520')
     assert_equal 'r520', c.text_tag