diff --git a/lib/grit.rb b/lib/grit.rb index 6f376f0..d574727 100644 --- a/lib/grit.rb +++ b/lib/grit.rb @@ -1,6 +1,7 @@ $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed # core +require 'fileutils' # stdlib diff --git a/lib/grit/repo.rb b/lib/grit/repo.rb index 5a65f34..e619ca9 100644 --- a/lib/grit/repo.rb +++ b/lib/grit/repo.rb @@ -1,6 +1,8 @@ module Grit class Repo + DAEMON_EXPORT_FILE = 'git-daemon-export-ok' + # The path of the git repo as a String attr_accessor :path attr_reader :bare @@ -199,6 +201,30 @@ module Grit self.git.archive(options, treeish, "| gzip") end + # Enable git-daemon serving of this repository by writing the + # git-daemon-export-ok file to its git directory + # + # Returns nothing + def enable_daemon_serve + if @bare + FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE)) + else + FileUtils.touch(File.join(self.path, '.git', DAEMON_EXPORT_FILE)) + end + end + + # Disable git-daemon serving of this repository by ensuring there is no + # git-daemon-export-ok file in its git directory + # + # Returns nothing + def disable_daemon_serve + if @bare + FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE)) + else + FileUtils.rm_f(File.join(self.path, '.git', DAEMON_EXPORT_FILE)) + end + end + # Pretty object inspection def inspect %Q{#} diff --git a/test/test_repo.rb b/test/test_repo.rb index 84c32d6..9926756 100644 --- a/test/test_repo.rb +++ b/test/test_repo.rb @@ -174,6 +174,20 @@ class TestRepo < Test::Unit::TestCase @r.archive_tar_gz end + # enable_daemon_serve + + def test_enable_daemon_serve + FileUtils.expects(:touch).with(File.join(@r.path, '.git', 'git-daemon-export-ok')) + @r.enable_daemon_serve + end + + # disable_daemon_serve + + def test_disable_daemon_serve + FileUtils.expects(:rm_f).with(File.join(@r.path, '.git', 'git-daemon-export-ok')) + @r.disable_daemon_serve + end + # inspect def test_inspect