Index: app/models/repository/git.rb =================================================================== --- app/models/repository/git.rb (revision 1322) +++ app/models/repository/git.rb (working copy) @@ -16,11 +16,37 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. require 'redmine/scm/adapters/git_adapter' - +require 'fileutils' class Repository::Git < Repository attr_protected :root_url validates_presence_of :url + before_save :clone_repository + after_destroy :remove_clone + + def identifier + self.project.identifier + end + + def clone_repository + return unless self.url.starts_with?("git://") + git_project_name = self.url.split("/").last.gsub(".git","") + + dir = "#{RAILS_ROOT}/repositories/git/#{identifier}/" + path_to_git_repository = dir + git_project_name + + FileUtils.rm_rf(dir) if File.exist?(dir) + FileUtils.mkdir_p(dir) + cmd = "cd #{dir} && git clone #{self.url}" + IO.popen(cmd, "r+") + self.url = "#{path_to_git_repository}/.git" + end + + def remove_clone + dir = "#{RAILS_ROOT}/repositories/git/#{identifier}" + FileUtils.rm_rf(dir) if File.exist?(dir) + end + def scm_adapter Redmine::Scm::Adapters::GitAdapter end Index: lib/redmine/scm/adapters/git_adapter.rb =================================================================== --- lib/redmine/scm/adapters/git_adapter.rb (revision 1322) +++ lib/redmine/scm/adapters/git_adapter.rb (working copy) @@ -22,6 +22,10 @@ module Adapters class GitAdapter < AbstractAdapter + def target(path) + url + end + # Git executable name GIT_BIN = "git"