]> source.dussan.org Git - redmine.git/commitdiff
Check that git changeset is not in the database before creating it (#1419).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Oct 2008 10:23:29 +0000 (10:23 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sat, 25 Oct 2008 10:23:29 +0000 (10:23 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1953 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/repository/git.rb
test/unit/repository_git_test.rb

index 2f440fe29b805ee64e4d3423da8ab47dc9fd035a..6fcb760e6dc70d798eeb77b971a3ef90e2744c8e 100644 (file)
@@ -45,20 +45,22 @@ class Repository::Git < Repository
 
       unless changesets.find_by_scmid(scm_revision)
         scm.revisions('', db_revision, nil, :reverse => true) do |revision|
-          transaction do
-            changeset = Changeset.create(:repository => self,
-                                         :revision => revision.identifier,
-                                         :scmid => revision.scmid,
-                                         :committer => revision.author, 
-                                         :committed_on => revision.time,
-                                         :comments => revision.message)
-            
-            revision.paths.each do |change|
-              Change.create(:changeset => changeset,
-                            :action => change[:action],
-                            :path => change[:path],
-                            :from_path => change[:from_path],
-                            :from_revision => change[:from_revision])
+          if changesets.find_by_scmid(revision.scmid.to_s).nil?
+            transaction do
+              changeset = Changeset.create!(:repository => self,
+                                           :revision => revision.identifier,
+                                           :scmid => revision.scmid,
+                                           :committer => revision.author, 
+                                           :committed_on => revision.time,
+                                           :comments => revision.message)
+              
+              revision.paths.each do |change|
+                Change.create!(:changeset => changeset,
+                              :action => change[:action],
+                              :path => change[:path],
+                              :from_path => change[:from_path],
+                              :from_revision => change[:from_revision])
+              end
             end
           end
         end
index 8a6f1ddd01eeaf4711d37dfa7cf731928e604125..0098273be6e7b7e39d564b390cd96e27fdbcf684 100644 (file)
@@ -42,7 +42,7 @@ class RepositoryGitTest < Test::Unit::TestCase
     def test_fetch_changesets_incremental
       @repository.fetch_changesets
       # Remove the 3 latest changesets
-      @repository.changesets.find(:all, :order => 'id DESC', :limit => 3).each(&:destroy)
+      @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
       @repository.reload
       assert_equal 3, @repository.changesets.count