2 # Copyright (C) 2012-2013 Gitorious AS
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # Creates a new bare Git repository at +path+
23 # sets git-daemon-export-ok if +set_export_ok+ is true (default)
24 def create(repos_path, set_export_ok = true)
25 FileUtils.mkdir_p(repos_path, :mode => 0750)
26 Dir.chdir(repos_path) do |path|
27 template = File.expand_path(File.join(File.dirname(__FILE__), "../data/git-template"))
28 git = Grit::Git.new(path)
29 git.init(:template => template)
30 post_create(path) if set_export_ok
34 # Clones a new bare Git repository at +target-path+ from +source_path+
35 # sets git-daemon-export-ok if +set_export_ok+ is true (default)
36 def clone(target_path, source_path, set_export_ok = true)
37 parent_path = File.expand_path(File.join(target_path, ".."))
38 FileUtils.mkdir_p(parent_path, :mode => 0750)
39 template = File.expand_path(File.join(File.dirname(__FILE__), "../data/git-template"))
40 git = Grit::Git.new(target_path)
41 git.clone({:bare => true, :template => template}, source_path, target_path)
42 post_create(target_path) if set_export_ok
45 def delete!(repos_path)
46 if repos_path.index(RepositoryRoot.default_base_path) == 0
47 FileUtils.rm_rf(repos_path)
53 def repository_has_commits?(repos_path)
54 Dir[File.join(repos_path, "refs/heads/*")].size > 0
59 FileUtils.touch(File.join(path, "git-daemon-export-ok"))
60 execute_command(%Q{GIT_DIR="#{path}" git update-server-info})
63 def execute_command(command)