summaryrefslogtreecommitdiffstats
path: root/lib/git_backend.rb
blob: 8fb9788c4bdeec015ecde90af884c7f9161e94ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require "fileutils"

class GitBackend
  class << self
    # Creates a new bare Git repository at +path+
    # sets git-daemon-export-ok if +set_export_ok+ is true (default)
    def create(repos_path, set_export_ok = true)
      FileUtils.mkdir_p(repos_path, :mode => 0750)
      Dir.chdir(repos_path) do |path| 
        Git.init(path, :repository => path)
        FileUtils.touch(File.join(path, "git-daemon-export-ok")) if set_export_ok
      end
    end
    
    # Clones a new bare Git repository at +target-path+ from +source_path+
    # sets git-daemon-export-ok if +set_export_ok+ is true (default)
    def clone(target_path, source_path, set_export_ok = true)
      Git.clone(source_path, target_path, :bare => true)
      FileUtils.touch(File.join(target_path, "git-daemon-export-ok")) if set_export_ok
    end
    
    def delete!(repos_path)
      if repos_path.index(GitoriousConfig["repository_base_path"]) == 0
        FileUtils.rm_rf(repos_path)
      else
        raise "bad path"
      end
    end
    
    def repository_has_commits?(repos_path)
      Dir[File.join(repos_path, "refs/heads/*")].size > 0
    end
  end
end