From: Nicolas Chuche Date: Mon, 22 Sep 2008 18:46:46 +0000 (+0000) Subject: add local cache repository for speed purpose (subversion) or for browsing a external... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=89b8bf3dc51dce032575efc1361ee8352d5654c4;p=redmine.git add local cache repository for speed purpose (subversion) or for browsing a external repository for SCM that can handle only local copy (git). git-svn-id: http://redmine.rubyforge.org/svn/branches/nbc@1899 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 1a82bb8ce..d798a2a5f 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -146,7 +146,8 @@ module RepositoriesHelper content_tag('p', form.password_field(:password, :size => 30, :name => 'ignore', :value => ((repository.new_record? || repository.password.blank?) ? '' : ('x'*15)), :onfocus => "this.value=''; this.name='repository[password]';", - :onchange => "this.name='repository[password]';")) + :onchange => "this.name='repository[password]';")) + + content_tag('p', form.check_box(:cache)) end def darcs_field_tags(form, repository) diff --git a/app/models/repository.rb b/app/models/repository.rb index 81e6647a2..9ff22330a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1,3 +1,4 @@ + # redMine - project management software # Copyright (C) 2006-2007 Jean-Philippe Lang # @@ -19,14 +20,14 @@ class Repository < ActiveRecord::Base belongs_to :project has_many :changesets, :order => "#{Changeset.table_name}.committed_on DESC, #{Changeset.table_name}.id DESC" has_many :changes, :through => :changesets - + # Raw SQL to delete changesets and changes in the database # has_many :changesets, :dependent => :destroy is too slow for big repositories before_destroy :clear_changesets - + # Checks if the SCM is enabled when creating a repository validate_on_create { |r| r.errors.add(:type, :activerecord_error_invalid) unless Setting.enabled_scm.include?(r.class.name.demodulize) } - + # Removes leading and trailing whitespace def url=(arg) write_attribute(:url, arg ? arg.to_s.strip : nil) @@ -38,7 +39,8 @@ class Repository < ActiveRecord::Base end def scm - @scm ||= self.scm_adapter.new url, root_url, login, password + init_cache if cache_path.blank? and respond_to?(:init_cache) + @scm ||= self.scm_adapter.new(url, root_url, login, password, cache_path) update_attribute(:root_url, @scm.root_url) if root_url.blank? @scm end @@ -122,9 +124,28 @@ class Repository < ActiveRecord::Base rescue nil end - + + def remove_cache + scm.remove_cache if cache + end + + def create_or_sync_cache + begin + scm.create_cache + rescue => e + # clean if problem in creation + scm.remove_cache + end + scm.synchronize + end + private - + + def repositories_cache_directory + dir = Setting.repositories_cache_directory.gsub(/^([^#{File::SEPARATOR}].*)/, RAILS_ROOT + '/\1') + return dir if File.directory?(dir) + end + def before_save # Strips url and root_url url.strip! diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index 2f440fe29..f6b9c2fef 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -21,6 +21,17 @@ class Repository::Git < Repository attr_protected :root_url validates_presence_of :url + before_destroy :remove_cache + + def init_cache + return unless dir = repositories_cache_directory + # we need to use a cache only if repository isn't local and dir exists + if url[/^(rsync|https?|git|ssh):\/\//] + update_attribute(:cache_path, dir + project.identifier) + update_attribute(:cache, true) + end + end + def scm_adapter Redmine::Scm::Adapters::GitAdapter end @@ -36,6 +47,8 @@ class Repository::Git < Repository end def fetch_changesets + create_or_sync_cache if cache + scm_info = scm.info if scm_info # latest revision found in database diff --git a/app/models/repository/subversion.rb b/app/models/repository/subversion.rb index 3981d6f4c..e29c42bb9 100644 --- a/app/models/repository/subversion.rb +++ b/app/models/repository/subversion.rb @@ -22,6 +22,16 @@ class Repository::Subversion < Repository validates_presence_of :url validates_format_of :url, :with => /^(http|https|svn|svn\+ssh|file):\/\/.+/i + before_destroy :remove_cache + + def init_cache + return unless dir = repositories_cache_directory + # we need to use a cache only if repository isn't local and dir exists + if cache and url[/^(svn|https?|svn\+ssh):\/\//] + update_attribute(:cache_path, dir + project.identifier) + end + end + def scm_adapter Redmine::Scm::Adapters::SubversionAdapter end @@ -41,6 +51,8 @@ class Repository::Subversion < Repository end def fetch_changesets + create_or_sync_cache if cache + scm_info = scm.info if scm_info # latest revision found in database diff --git a/app/models/setting.rb b/app/models/setting.rb index 072afa0db..c59925a9f 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -161,4 +161,14 @@ private setting = find_by_name(name) setting ||= new(:name => name, :value => @@available_settings[name]['default']) if @@available_settings.has_key? name end + + protected + + def validate + if self.name.to_s == "repositories_cache_directory" and not File.directory?(self.value.to_s) + logger.error("Le repertoire #{self.value.to_s} n'existe pas") + errors.add("Le repertoire #{self.value.to_s} n'existe pas") + end + end + end diff --git a/app/views/settings/_repositories.rhtml b/app/views/settings/_repositories.rhtml index a8c924430..fb4e88f4c 100644 --- a/app/views/settings/_repositories.rhtml +++ b/app/views/settings/_repositories.rhtml @@ -17,6 +17,9 @@

<%= text_field_tag 'settings[repositories_encodings]', Setting.repositories_encodings, :size => 60 %>
<%= l(:text_comma_separated) %>

+

+<%= text_field_tag 'settings[repositories_cache_directory]', Setting.repositories_cache_directory, :size => 60 %>

+

<%= select_tag 'settings[commit_logs_encoding]', options_for_select(Setting::ENCODINGS, Setting.commit_logs_encoding) %>

diff --git a/config/settings.yml b/config/settings.yml index e1ad341de..52f7bed87 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -124,6 +124,8 @@ sequential_project_identifiers: # multiple values accepted, comma separated repositories_encodings: default: '' +repositories_cache_directory: + default: 'tmp/scm/' # encoding used to convert commit logs to UTF-8 commit_logs_encoding: default: 'UTF-8' diff --git a/db/migrate/099_add_local_copy.rb b/db/migrate/099_add_local_copy.rb new file mode 100644 index 000000000..2532f87c5 --- /dev/null +++ b/db/migrate/099_add_local_copy.rb @@ -0,0 +1,12 @@ +class AddLocalCopy < ActiveRecord::Migration + def self.up + add_column :repositories, :cache, :boolean + add_column :repositories, :cache_path, :string, :limit => 255, :default => "" + + end + + def self.down + remove_column :repositories, :cache + remove_column :repositories, :cache_path + end +end diff --git a/lang/bg.yml b/lang/bg.yml index f8d2e5e2c..7c171a461 100644 --- a/lang/bg.yml +++ b/lang/bg.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/ca.yml b/lang/ca.yml index 30348b060..0641d781b 100644 --- a/lang/ca.yml +++ b/lang/ca.yml @@ -642,3 +642,5 @@ field_comments: Comment setting_commit_logs_encoding: Commit messages encoding label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/cs.yml b/lang/cs.yml index cf2cb0992..29babd3a9 100644 --- a/lang/cs.yml +++ b/lang/cs.yml @@ -645,3 +645,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/da.yml b/lang/da.yml index 0ee1b2512..92f5501a2 100644 --- a/lang/da.yml +++ b/lang/da.yml @@ -641,3 +641,5 @@ default_activity_development: Udvikling enumeration_issue_priorities: Sagsprioriteter enumeration_doc_categories: Dokumentkategorier enumeration_activities: Aktiviteter (tidsregistrering) +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/de.yml b/lang/de.yml index 7aa2d971b..dbbb1183d 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -641,3 +641,5 @@ default_activity_development: Entwicklung enumeration_issue_priorities: Ticket-Prioritäten enumeration_doc_categories: Dokumentenkategorien enumeration_activities: Aktivitäten (Zeiterfassung) +field_cache: Local cache +setting_repositories_cache_directory: Cache directory for repositories diff --git a/lang/en.yml b/lang/en.yml index 8a73a3992..22543af26 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -184,6 +184,7 @@ field_searchable: Searchable field_default_value: Default value field_comments_sorting: Display comments field_parent_title: Parent page +field_cache: Local cache setting_app_title: Application title setting_app_subtitle: Application subtitle @@ -221,6 +222,7 @@ setting_enabled_scm: Enabled SCM setting_mail_handler_api_enabled: Enable WS for incoming emails setting_mail_handler_api_key: API key setting_sequential_project_identifiers: Generate sequential project identifiers +setting_repositories_cache_directory: Cache directory for repositories project_module_issue_tracking: Issue tracking project_module_time_tracking: Time tracking diff --git a/lang/es.yml b/lang/es.yml index ae367d842..05d42549c 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -643,3 +643,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/fi.yml b/lang/fi.yml index 225563b37..d674568ef 100644 --- a/lang/fi.yml +++ b/lang/fi.yml @@ -640,3 +640,5 @@ setting_commit_logs_encoding: Commit messages encoding notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/fr.yml b/lang/fr.yml index b64078068..77c358a9b 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -221,6 +221,7 @@ setting_enabled_scm: SCM activés setting_mail_handler_api_enabled: "Activer le WS pour la réception d'emails" setting_mail_handler_api_key: Clé de protection de l'API setting_sequential_project_identifiers: Générer des identifiants de projet séquentiels +setting_repositories_cache_directory: Répertoire du cache pour les dépôts project_module_issue_tracking: Suivi des demandes project_module_time_tracking: Suivi du temps passé @@ -641,3 +642,4 @@ enumeration_issue_priorities: Priorités des demandes enumeration_doc_categories: Catégories des documents enumeration_activities: Activités (suivi du temps) notice_unable_delete_version: Unable to delete version +field_cache: Cache local diff --git a/lang/he.yml b/lang/he.yml index 07962d2de..f95843b85 100644 --- a/lang/he.yml +++ b/lang/he.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/hu.yml b/lang/hu.yml index 3a3d18a12..28008aabb 100644 --- a/lang/hu.yml +++ b/lang/hu.yml @@ -641,3 +641,5 @@ setting_sequential_project_identifiers: Szekvenciális projekt azonosítók gene notice_unable_delete_version: A verziót nem lehet törölni label_renamed: átnevezve label_copied: lemásolva +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/it.yml b/lang/it.yml index bca755605..20e53472c 100644 --- a/lang/it.yml +++ b/lang/it.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Genera progetti con identificativi in se notice_unable_delete_version: Impossibile cancellare la versione label_renamed: rinominato label_copied: copiato +field_cache: Local cache +setting_repositories_cache_directory: Cache directory for repositories diff --git a/lang/ja.yml b/lang/ja.yml index 4e46212b2..95c632b8d 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -641,3 +641,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/ko.yml b/lang/ko.yml index c23ea71cd..0d96274f2 100644 --- a/lang/ko.yml +++ b/lang/ko.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/lt.yml b/lang/lt.yml index f29c28c4f..ffb831575 100644 --- a/lang/lt.yml +++ b/lang/lt.yml @@ -642,3 +642,5 @@ button_quote: Cituoti notice_unable_delete_version: Neimanoma panaikinti versiją label_renamed: pervardintas label_copied: nukopijuotas +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/nl.yml b/lang/nl.yml index 8fd96d1c1..18954534a 100644 --- a/lang/nl.yml +++ b/lang/nl.yml @@ -643,3 +643,5 @@ setting_sequential_project_identifiers: Genereer sequentiele project identiteite notice_unable_delete_version: Onmogelijk om deze versie te verwijderen. label_renamed: hernoemt label_copied: gekopieerd +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/no.yml b/lang/no.yml index 8cd6952c6..9b3be9ae1 100644 --- a/lang/no.yml +++ b/lang/no.yml @@ -641,3 +641,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/pl.yml b/lang/pl.yml index 5003db739..dc49dce4b 100644 --- a/lang/pl.yml +++ b/lang/pl.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/pt-br.yml b/lang/pt-br.yml index 3e314af8c..74ee2486c 100644 --- a/lang/pt-br.yml +++ b/lang/pt-br.yml @@ -641,3 +641,5 @@ enumeration_activities: Atividades (time tracking) notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/pt.yml b/lang/pt.yml index e968ef3b4..98f13108b 100644 --- a/lang/pt.yml +++ b/lang/pt.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Gerar identificador sequencial notice_unable_delete_version: Impossível apagar esta versão label_renamed: renomeado label_copied: copiado +field_cache: Local cache +setting_repositories_cache_directory: Cache directory for repositories diff --git a/lang/ro.yml b/lang/ro.yml index 94278256e..1f399989c 100644 --- a/lang/ro.yml +++ b/lang/ro.yml @@ -640,3 +640,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/ru.yml b/lang/ru.yml index ce5e43b7d..bcc7121b2 100644 --- a/lang/ru.yml +++ b/lang/ru.yml @@ -673,3 +673,5 @@ text_user_wrote: '%s написал(а):' text_wiki_destroy_confirmation: Вы уверены, что хотите удалить данную Wiki и все содержимое? text_workflow_edit: Выберите роль и трекер для редактирования последовательности состояний +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/sr.yml b/lang/sr.yml index 720dfcdff..3ac7b7cd9 100644 --- a/lang/sr.yml +++ b/lang/sr.yml @@ -641,3 +641,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/sv.yml b/lang/sv.yml index 393ade818..5df46232d 100644 --- a/lang/sv.yml +++ b/lang/sv.yml @@ -641,3 +641,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/th.yml b/lang/th.yml index 362e44756..ca2db8bcc 100644 --- a/lang/th.yml +++ b/lang/th.yml @@ -643,3 +643,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/tr.yml b/lang/tr.yml index ba9c0b41b..56bf3311a 100644 --- a/lang/tr.yml +++ b/lang/tr.yml @@ -641,3 +641,5 @@ general_csv_decimal_separator: '.' notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/uk.yml b/lang/uk.yml index de5f65eb0..dd3954a90 100644 --- a/lang/uk.yml +++ b/lang/uk.yml @@ -642,3 +642,5 @@ setting_sequential_project_identifiers: Generate sequential project identifiers notice_unable_delete_version: Unable to delete version label_renamed: renamed label_copied: copied +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/zh-tw.yml b/lang/zh-tw.yml index 6feb0a0e8..3ddf1402e 100644 --- a/lang/zh-tw.yml +++ b/lang/zh-tw.yml @@ -641,3 +641,5 @@ default_activity_development: 開發 enumeration_issue_priorities: 項目優先權 enumeration_doc_categories: 文件分類 enumeration_activities: 活動 (時間追蹤) +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lang/zh.yml b/lang/zh.yml index d2e571b4d..cd2d3e407 100644 --- a/lang/zh.yml +++ b/lang/zh.yml @@ -641,3 +641,5 @@ default_activity_development: 开发 enumeration_issue_priorities: 问题优先级 enumeration_doc_categories: 文档类别 enumeration_activities: 活动(时间跟踪) +setting_repositories_cache_directory: Cache directory for repositories +field_cache: Local cache diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb index 9f400880d..7e09d1611 100644 --- a/lib/redmine/scm/adapters/abstract_adapter.rb +++ b/lib/redmine/scm/adapters/abstract_adapter.rb @@ -47,11 +47,17 @@ module Redmine end end - def initialize(url, root_url=nil, login=nil, password=nil) + def initialize(url, root_url=nil, login=nil, password=nil, cache_path=nil) @url = url @login = login if login && !login.empty? @password = (password || "") if @login - @root_url = root_url.blank? ? retrieve_root_url : root_url + + if cache_path.blank? + @root_url = root_url.blank? ? retrieve_root_url : root_url + else + @orig_url = @url + @url = @root_url = cache_path + end end def adapter_name @@ -145,7 +151,22 @@ module Redmine end end + def remove_cache + remove_directory(@root_url) if not @orig_url.blank? and File.directory?(@root_url) + end + private + def remove_directory(path) + Dir.entries(path).each do |f| + next if %w[. ..].include?(f) + name = "#{path}/#{f}" + File.directory?(name) ? remove_directory(name) : File.unlink(name) + end + Dir.rmdir path + rescue Errno::ENOENT => e + logger.error(e.to_s) + end + def retrieve_root_url info = self.info info ? info.root_url : nil @@ -194,7 +215,7 @@ module Redmine self.class.strip_credential(cmd) end end - + class Entries < Array def sort_by_name sort {|x,y| diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 30d624001..c1f3e335b 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -25,6 +25,11 @@ module Redmine # Git executable name GIT_BIN = "git" + def initialize(url, root_url=nil, login=nil, password=nil, cache_path=nil) + super(url, root_url, login, password, cache_path) + @url += "/.git/" unless cache_path.blank? + end + # Get the revision of a particuliar file def get_rev (rev,path) @@ -263,9 +268,20 @@ module Redmine return nil if $? && $?.exitstatus != 0 cat end + + def create_cache + cmd = "#{GIT_BIN} clone #{@orig_url} #{@root_url}" + shellout(cmd) { |io| io.read } + end + + def synchronize + return unless File.directory?(@url) + cmd = "#{GIT_BIN} --git-dir #{@url} pull" + shellout(cmd) + end + end end end - end diff --git a/lib/redmine/scm/adapters/subversion_adapter.rb b/lib/redmine/scm/adapters/subversion_adapter.rb index 2b7f0192e..109e9e756 100644 --- a/lib/redmine/scm/adapters/subversion_adapter.rb +++ b/lib/redmine/scm/adapters/subversion_adapter.rb @@ -25,7 +25,7 @@ module Redmine # SVN executable name SVN_BIN = "svn" - + class << self def client_version @@client_version ||= (svn_binary_version || []) @@ -213,6 +213,18 @@ module Redmine return nil if $? && $?.exitstatus != 0 blame end + + def create_cache + return if @orig_url.blank? + cmd = "#{SVN_BIN} checkout --non-interactive #{@orig_url} #{@root_url}" + shellout(cmd) { |io| io.read } + end + + def synchronize + return if @orig_url.blank? + cmd = "#{SVN_BIN} update --non-interactive" + Dir.chdir(@root_url) { shellout(cmd) { |io| io.read } } + end private @@ -222,6 +234,7 @@ module Redmine str << " --password #{shell_quote(@password)}" unless @login.blank? || @password.blank? str end + end end end diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 9ea9fdd45..0973c7fdb 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -127,4 +127,26 @@ class RepositoryTest < Test::Unit::TestCase assert_equal ':pserver:login:password@host:/path/to/the/repository', repository.url assert_equal 'foo', repository.root_url end + + def test_local_cache + dir = Setting.repositories_cache_directory.gsub(/^([^#{File::SEPARATOR}].*)/, RAILS_ROOT + '/\1') + + project = projects(:projects_001) + + repository = Repository::Git.new(:project => Project.find_by_name(project.name), :url => "git://github.com/olabini/paipr.git") + repository.scm + assert_equal(dir + project.identifier, repository.cache_path) + + repository = Repository::Git.new(:project => Project.find(:first), :url => "/var/cache/git/paipr/.git") + repository.init_cache + assert repository.cache_path.blank? + + repository = Repository::Subversion.new(:project => Project.find(:first), :url => "svn://github.com/olabini/paipr.git") + repository.init_cache + assert repository.cache_path.blank? + + repository = Repository::Subversion.new(:project => Project.find_by_name(project.name), :url => "svn://github.com/olabini/paipr.git", :cache => true) + repository.init_cache + assert_equal(dir + project.identifier, repository.cache_path) + end end