From 8236563d6bdc361ba0a0d9b292442fa5d2a39e07 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 25 Oct 2008 10:23:29 +0000 Subject: [PATCH] Check that git changeset is not in the database before creating it (#1419). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@1953 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/repository/git.rb | 30 ++++++++++++++++-------------- test/unit/repository_git_test.rb | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index 2f440fe29..6fcb760e6 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -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 diff --git a/test/unit/repository_git_test.rb b/test/unit/repository_git_test.rb index 8a6f1ddd0..0098273be 100644 --- a/test/unit/repository_git_test.rb +++ b/test/unit/repository_git_test.rb @@ -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