diff --git a/git/app/models/repository/darcs.rb b/git/app/models/repository/darcs.rb index 48cc246fb..cc608d370 100644 --- a/git/app/models/repository/darcs.rb +++ b/git/app/models/repository/darcs.rb @@ -47,18 +47,19 @@ class Repository::Darcs < Repository def diff(path, rev, rev_to, type) patch_from = changesets.find_by_revision(rev) + return nil if patch_from.nil? patch_to = changesets.find_by_revision(rev_to) if rev_to if path.blank? path = patch_from.changes.collect{|change| change.path}.join(' ') end - scm.diff(path, patch_from.scmid, patch_to.scmid, type) + patch_from ? scm.diff(path, patch_from.scmid, patch_to ? patch_to.scmid : nil, type) : nil end def fetch_changesets scm_info = scm.info if scm_info db_last_id = latest_changeset ? latest_changeset.scmid : nil - next_rev = latest_changeset ? latest_changeset.revision + 1 : 1 + next_rev = latest_changeset ? latest_changeset.revision.to_i + 1 : 1 # latest revision in the repository scm_revision = scm_info.lastrev.scmid unless changesets.find_by_scmid(scm_revision) @@ -71,9 +72,7 @@ class Repository::Darcs < Repository :committer => revision.author, :committed_on => revision.time, :comments => revision.message) - - next if changeset.new_record? - + revision.paths.each do |change| Change.create(:changeset => changeset, :action => change[:action], diff --git a/git/lib/redmine/scm/adapters/darcs_adapter.rb b/git/lib/redmine/scm/adapters/darcs_adapter.rb index 2955b26dc..cd8610121 100644 --- a/git/lib/redmine/scm/adapters/darcs_adapter.rb +++ b/git/lib/redmine/scm/adapters/darcs_adapter.rb @@ -102,8 +102,12 @@ module Redmine def diff(path, identifier_from, identifier_to=nil, type="inline") path = '*' if path.blank? cmd = "#{DARCS_BIN} diff --repodir #{@url}" - cmd << " --to-match \"hash #{identifier_from}\"" - cmd << " --from-match \"hash #{identifier_to}\"" if identifier_to + if identifier_to.nil? + cmd << " --match \"hash #{identifier_from}\"" + else + cmd << " --to-match \"hash #{identifier_from}\"" + cmd << " --from-match \"hash #{identifier_to}\"" + end cmd << " -u #{path}" diff = [] shellout(cmd) do |io| diff --git a/git/test/fixtures/repositories/darcs_repository.tar.gz b/git/test/fixtures/repositories/darcs_repository.tar.gz new file mode 100644 index 000000000..ba4d8d04c Binary files /dev/null and b/git/test/fixtures/repositories/darcs_repository.tar.gz differ diff --git a/git/test/functional/repositories_darcs_controller_test.rb b/git/test/functional/repositories_darcs_controller_test.rb new file mode 100644 index 000000000..fc77b8747 --- /dev/null +++ b/git/test/functional/repositories_darcs_controller_test.rb @@ -0,0 +1,94 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' +require 'repositories_controller' + +# Re-raise errors caught by the controller. +class RepositoriesController; def rescue_action(e) raise e end; end + +class RepositoriesDarcsControllerTest < Test::Unit::TestCase + fixtures :projects, :users, :roles, :members, :repositories, :enabled_modules + + # No '..' in the repository path + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository' + + def setup + @controller = RepositoriesController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + User.current = nil + Repository::Darcs.create(:project => Project.find(3), :url => REPOSITORY_PATH) + end + + if File.directory?(REPOSITORY_PATH) + def test_show + get :show, :id => 3 + assert_response :success + assert_template 'show' + assert_not_nil assigns(:entries) + assert_not_nil assigns(:changesets) + end + + def test_browse_root + get :browse, :id => 3 + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entries) + assert_equal 3, assigns(:entries).size + assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} + assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} + end + + def test_browse_directory + get :browse, :id => 3, :path => ['images'] + assert_response :success + assert_template 'browse' + assert_not_nil assigns(:entries) + assert_equal 2, assigns(:entries).size + entry = assigns(:entries).detect {|e| e.name == 'edit.png'} + assert_not_nil entry + assert_equal 'file', entry.kind + assert_equal 'images/edit.png', entry.path + end + + def test_changes + get :changes, :id => 3, :path => ['images', 'edit.png'] + assert_response :success + assert_template 'changes' + assert_tag :tag => 'h2', :content => 'edit.png' + end + + def test_diff + Project.find(3).repository.fetch_changesets + # Full diff of changeset 5 + get :diff, :id => 3, :rev => 5 + assert_response :success + assert_template 'diff' + # Line 22 removed + assert_tag :tag => 'th', + :content => /22/, + :sibling => { :tag => 'td', + :attributes => { :class => /diff_out/ }, + :content => /def remove/ } + end + else + puts "Darcs test repository NOT FOUND. Skipping functional tests !!!" + def test_fake; assert true end + end +end diff --git a/git/test/unit/repository_darcs_test.rb b/git/test/unit/repository_darcs_test.rb new file mode 100644 index 000000000..1228976f1 --- /dev/null +++ b/git/test/unit/repository_darcs_test.rb @@ -0,0 +1,55 @@ +# redMine - project management software +# Copyright (C) 2006-2008 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.dirname(__FILE__) + '/../test_helper' + +class RepositoryDarcsTest < Test::Unit::TestCase + fixtures :projects + + # No '..' in the repository path + REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/darcs_repository' + + def setup + @project = Project.find(1) + assert @repository = Repository::Darcs.create(:project => @project, :url => REPOSITORY_PATH) + end + + if File.directory?(REPOSITORY_PATH) + def test_fetch_changesets_from_scratch + @repository.fetch_changesets + @repository.reload + + assert_equal 6, @repository.changesets.count + assert_equal 13, @repository.changes.count + assert_equal "Initial commit.", @repository.changesets.find_by_revision(1).comments + end + + def test_fetch_changesets_incremental + @repository.fetch_changesets + # Remove changesets with revision > 3 + @repository.changesets.find(:all, :conditions => 'revision > 3').each(&:destroy) + @repository.reload + assert_equal 3, @repository.changesets.count + + @repository.fetch_changesets + assert_equal 6, @repository.changesets.count + end + else + puts "Darcs test repository NOT FOUND. Skipping unit tests !!!" + def test_fake; assert true end + end +end