Patch #986 ยป clone_remote_git.diff
| app/models/repository/git.rb (working copy) | ||
|---|---|---|
|
# 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
|
||
| lib/redmine/scm/adapters/git_adapter.rb (working copy) | ||
|---|---|---|
|
module Adapters
|
||
|
class GitAdapter < AbstractAdapter
|
||
|
|
||
|
def target(path)
|
||
|
url
|
||
|
end
|
||
|
|
||
|
# Git executable name
|
||
|
GIT_BIN = "git"
|
||