@@ -1,68 +1,70 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com |
|
3 | # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require 'redmine/scm/adapters/git_adapter' |
|
18 | require 'redmine/scm/adapters/git_adapter' | |
19 |
|
19 | |||
20 | class Repository::Git < Repository |
|
20 | class Repository::Git < Repository | |
21 | attr_protected :root_url |
|
21 | attr_protected :root_url | |
22 | validates_presence_of :url |
|
22 | validates_presence_of :url | |
23 |
|
23 | |||
24 | def scm_adapter |
|
24 | def scm_adapter | |
25 | Redmine::Scm::Adapters::GitAdapter |
|
25 | Redmine::Scm::Adapters::GitAdapter | |
26 | end |
|
26 | end | |
27 |
|
27 | |||
28 | def self.scm_name |
|
28 | def self.scm_name | |
29 | 'Git' |
|
29 | 'Git' | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | def changesets_for_path(path) |
|
32 | def changesets_for_path(path) | |
33 | Change.find(:all, :include => :changeset, |
|
33 | Change.find(:all, :include => :changeset, | |
34 | :conditions => ["repository_id = ? AND path = ?", id, path], |
|
34 | :conditions => ["repository_id = ? AND path = ?", id, path], | |
35 | :order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset) |
|
35 | :order => "committed_on DESC, #{Changeset.table_name}.revision DESC").collect(&:changeset) | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def fetch_changesets |
|
38 | def fetch_changesets | |
39 | scm_info = scm.info |
|
39 | scm_info = scm.info | |
40 | if scm_info |
|
40 | if scm_info | |
41 | # latest revision found in database |
|
41 | # latest revision found in database | |
42 | db_revision = latest_changeset ? latest_changeset.revision : nil |
|
42 | db_revision = latest_changeset ? latest_changeset.revision : nil | |
43 | # latest revision in the repository |
|
43 | # latest revision in the repository | |
44 | scm_revision = scm_info.lastrev.scmid |
|
44 | scm_revision = scm_info.lastrev.scmid | |
45 |
|
45 | |||
46 | unless changesets.find_by_scmid(scm_revision) |
|
46 | unless changesets.find_by_scmid(scm_revision) | |
47 | scm.revisions('', db_revision, nil, :reverse => true) do |revision| |
|
47 | scm.revisions('', db_revision, nil, :reverse => true) do |revision| | |
48 | transaction do |
|
48 | if changesets.find_by_scmid(revision.scmid.to_s).nil? | |
49 | changeset = Changeset.create(:repository => self, |
|
49 | transaction do | |
50 | :revision => revision.identifier, |
|
50 | changeset = Changeset.create!(:repository => self, | |
51 |
|
|
51 | :revision => revision.identifier, | |
52 |
|
|
52 | :scmid => revision.scmid, | |
53 |
:committe |
|
53 | :committer => revision.author, | |
54 |
:commen |
|
54 | :committed_on => revision.time, | |
55 |
|
55 | :comments => revision.message) | ||
56 | revision.paths.each do |change| |
|
56 | ||
57 | Change.create(:changeset => changeset, |
|
57 | revision.paths.each do |change| | |
58 | :action => change[:action], |
|
58 | Change.create!(:changeset => changeset, | |
59 |
|
|
59 | :action => change[:action], | |
60 |
: |
|
60 | :path => change[:path], | |
61 |
:from_ |
|
61 | :from_path => change[:from_path], | |
|
62 | :from_revision => change[:from_revision]) | |||
|
63 | end | |||
62 | end |
|
64 | end | |
63 | end |
|
65 | end | |
64 | end |
|
66 | end | |
65 | end |
|
67 | end | |
66 | end |
|
68 | end | |
67 | end |
|
69 | end | |
68 | end |
|
70 | end |
@@ -1,56 +1,56 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2007 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.dirname(__FILE__) + '/../test_helper' |
|
18 | require File.dirname(__FILE__) + '/../test_helper' | |
19 |
|
19 | |||
20 | class RepositoryGitTest < Test::Unit::TestCase |
|
20 | class RepositoryGitTest < Test::Unit::TestCase | |
21 | fixtures :projects |
|
21 | fixtures :projects | |
22 |
|
22 | |||
23 | # No '..' in the repository path |
|
23 | # No '..' in the repository path | |
24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' |
|
24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' | |
25 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
25 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? | |
26 |
|
26 | |||
27 | def setup |
|
27 | def setup | |
28 | @project = Project.find(1) |
|
28 | @project = Project.find(1) | |
29 | assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH) |
|
29 | assert @repository = Repository::Git.create(:project => @project, :url => REPOSITORY_PATH) | |
30 | end |
|
30 | end | |
31 |
|
31 | |||
32 | if File.directory?(REPOSITORY_PATH) |
|
32 | if File.directory?(REPOSITORY_PATH) | |
33 | def test_fetch_changesets_from_scratch |
|
33 | def test_fetch_changesets_from_scratch | |
34 | @repository.fetch_changesets |
|
34 | @repository.fetch_changesets | |
35 | @repository.reload |
|
35 | @repository.reload | |
36 |
|
36 | |||
37 | assert_equal 6, @repository.changesets.count |
|
37 | assert_equal 6, @repository.changesets.count | |
38 | assert_equal 11, @repository.changes.count |
|
38 | assert_equal 11, @repository.changes.count | |
39 | assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find(:first, :order => 'id ASC').comments |
|
39 | assert_equal "Initial import.\nThe repository contains 3 files.", @repository.changesets.find(:first, :order => 'id ASC').comments | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | def test_fetch_changesets_incremental |
|
42 | def test_fetch_changesets_incremental | |
43 | @repository.fetch_changesets |
|
43 | @repository.fetch_changesets | |
44 | # Remove the 3 latest changesets |
|
44 | # Remove the 3 latest changesets | |
45 | @repository.changesets.find(:all, :order => 'id DESC', :limit => 3).each(&:destroy) |
|
45 | @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy) | |
46 | @repository.reload |
|
46 | @repository.reload | |
47 | assert_equal 3, @repository.changesets.count |
|
47 | assert_equal 3, @repository.changesets.count | |
48 |
|
48 | |||
49 | @repository.fetch_changesets |
|
49 | @repository.fetch_changesets | |
50 | assert_equal 6, @repository.changesets.count |
|
50 | assert_equal 6, @repository.changesets.count | |
51 | end |
|
51 | end | |
52 | else |
|
52 | else | |
53 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
53 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" | |
54 | def test_fake; assert true end |
|
54 | def test_fake; assert true end | |
55 | end |
|
55 | end | |
56 | end |
|
56 | end |
General Comments 0
You need to be logged in to leave comments.
Login now