clone_remote_git.diff

Michael Bumann, 2008-04-03 19:27

Download (1.68 KB)

View differences:

app/models/repository/git.rb (working copy)
16 16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 17

  
18 18
require 'redmine/scm/adapters/git_adapter'
19

  
19
require 'fileutils'
20 20
class Repository::Git < Repository
21 21
  attr_protected :root_url
22 22
  validates_presence_of :url
23 23

  
24
  before_save :clone_repository
25
  after_destroy :remove_clone
26
  
27
  def identifier 
28
    self.project.identifier
29
  end
30
  
31
  def clone_repository
32
    return unless self.url.starts_with?("git://")
33
    git_project_name = self.url.split("/").last.gsub(".git","")
34
    
35
    dir = "#{RAILS_ROOT}/repositories/git/#{identifier}/"
36
    path_to_git_repository = dir + git_project_name
37
    
38
    FileUtils.rm_rf(dir) if File.exist?(dir)
39
    FileUtils.mkdir_p(dir)
40
    cmd = "cd #{dir} && git clone #{self.url}"
41
    IO.popen(cmd, "r+")
42
    self.url = "#{path_to_git_repository}/.git"
43
  end
44
  
45
  def remove_clone
46
    dir = "#{RAILS_ROOT}/repositories/git/#{identifier}"
47
    FileUtils.rm_rf(dir) if File.exist?(dir)
48
  end
49
  
24 50
  def scm_adapter
25 51
    Redmine::Scm::Adapters::GitAdapter
26 52
  end
lib/redmine/scm/adapters/git_adapter.rb (working copy)
22 22
    module Adapters    
23 23
      class GitAdapter < AbstractAdapter
24 24
        
25
        def target(path)
26
          url
27
        end
28
        
25 29
        # Git executable name
26 30
        GIT_BIN = "git"
27 31