diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/git.rb | 4 | ||||
-rw-r--r-- | lib/git/base.rb | 13 | ||||
-rw-r--r-- | lib/git/lib.rb | 18 |
3 files changed, 24 insertions, 11 deletions
@@ -48,8 +48,8 @@ module Git # it expects not to be able to use a working directory # so you can't checkout stuff, commit things, etc. # but you can do most read operations - def self.bare(git_dir) - Base.bare(git_dir) + def self.bare(git_dir, options = {}) + Base.bare(git_dir, options) end # open an existing git working directory diff --git a/lib/git/base.rb b/lib/git/base.rb index 2986864..fe0b2e7 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -7,10 +7,14 @@ module Git @index = nil @lib = nil + @logger = nil # opens a bare Git Repository - no working directory options - def self.bare(git_dir) - self.new :repository => git_dir + def self.bare(git_dir, opts = {}) + default = {:repository => git_dir} + git_options = default.merge(opts) + + self.new(git_options) end # opens a new Git Project from a working directory @@ -67,6 +71,9 @@ module Git options[:repository] = File.join(working_dir, '.git') if !options[:repository] options[:index] = File.join(working_dir, '.git', 'index') if !options[:index] end + if options[:log] + @logger = options[:log] + end @working_directory = Git::WorkingDirectory.new(options[:working_directory]) if options[:working_directory] @repository = Git::Repository.new(options[:repository]) if options[:repository] @@ -199,7 +206,7 @@ module Git # actual 'git' forked system calls. At some point I hope to replace the Git::Lib # class with one that uses native methods or libgit C bindings def lib - @lib ||= Git::Lib.new(self) + @lib ||= Git::Lib.new(self, @logger) end # will run a grep for 'string' on the HEAD of the git repository diff --git a/lib/git/lib.rb b/lib/git/lib.rb index c6d3580..293e00b 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -11,8 +11,10 @@ module Git @git_index_file = nil @git_work_dir = nil @path = nil - - def initialize(base = nil) + + @logger = nil + + def initialize(base = nil, logger = nil) if base.is_a?(Git::Base) @git_dir = base.repo.path @git_index_file = base.index.path if base.index @@ -22,6 +24,9 @@ module Git @git_index_file = base[:index] @git_work_dir = base[:working_directory] end + if logger + @logger = logger + end end def init @@ -481,10 +486,11 @@ module Git out = `git #{cmd} #{opts} 2>&1`.chomp end - #puts git_cmd - #puts out - #puts - + if @logger + @logger.info(git_cmd) + @logger.debug(out) + end + if $?.exitstatus > 0 if $?.exitstatus == 1 && out == '' return '' |