| 1 |
require "fileutils" |
| 2 |
|
| 3 |
class GitBackend |
| 4 |
class << self |
| 5 |
|
| 6 |
|
| 7 |
def create(repos_path, set_export_ok = true) |
| 8 |
FileUtils.mkdir_p(repos_path, :mode => 0750) |
| 9 |
Dir.chdir(repos_path) do |path| |
| 10 |
template = File.expand_path(File.join(File.dirname(__FILE__), "../data/git-template")) |
| 11 |
git = Grit::Git.new(path) |
| 12 |
git.init({}, "--template=#{template}") |
| 13 |
post_create(path) if set_export_ok |
| 14 |
end |
| 15 |
end |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
def clone(target_path, source_path, set_export_ok = true) |
| 20 |
template = File.expand_path(File.join(File.dirname(__FILE__), "../data/git-template")) |
| 21 |
git = Grit::Git.new(target_path) |
| 22 |
git.clone({:bare => true}, "--template=#{template}", source_path, target_path) |
| 23 |
post_create(target_path) if set_export_ok |
| 24 |
end |
| 25 |
|
| 26 |
def delete!(repos_path) |
| 27 |
if repos_path.index(GitoriousConfig["repository_base_path"]) == 0 |
| 28 |
FileUtils.rm_rf(repos_path) |
| 29 |
else |
| 30 |
raise "bad path" |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
def repository_has_commits?(repos_path) |
| 35 |
Dir[File.join(repos_path, "refs/heads/*")].size > 0 |
| 36 |
end |
| 37 |
|
| 38 |
protected |
| 39 |
def post_create(path) |
| 40 |
FileUtils.touch(File.join(path, "git-daemon-export-ok")) |
| 41 |
execute_command(%Q{GIT_DIR="#{path}" git-update-server-info}) |
| 42 |
end |
| 43 |
|
| 44 |
def execute_command(command) |
| 45 |
system(command) |
| 46 |
end |
| 47 |
end |
| 48 |
end |