From fde3263abc5c7866aa7dce7aef28eacaa33d7664 Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Sat, 10 Nov 2007 12:43:33 -0800 Subject: few hours work - diff is done --- lib/git/base.rb | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) (limited to 'lib/git/base.rb') diff --git a/lib/git/base.rb b/lib/git/base.rb index 8170065..1111887 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -22,19 +22,33 @@ module Git self.new(git_options) end - def initialize(options = {}) - @working_directory = Git::Repository.new(options[:working_directory]) if options[:working_directory] - @repository = Git::Repository.new(options[:repository]) if options[:repository] - @index = Git::Index.new(options[:index]) if options[:index] + def self.init(working_dir, opts = {}) + default = {:working_directory => working_dir, + :repository => File.join(working_dir, '.git')} + git_options = default.merge(opts) + + if git_options[:working_directory] + # if !working_dir, make it + FileUtils.mkdir_p(git_options[:working_directory]) if !File.directory?(git_options[:working_directory]) + end + + # run git_init there + Git::Lib.new(git_options).init + + self.new(git_options) end - + def self.clone raise NotImplementedError end - - def self.init - raise NotImplementedError + + def initialize(options = {}) + @working_directory = Git::WorkingDirectory.new(options[:working_directory]) if options[:working_directory] + @repository = Git::Repository.new(options[:repository]) if options[:repository] + @index = Git::Index.new(options[:index]) if options[:index] end + + def dir @@ -49,6 +63,23 @@ module Git @index end + + #g.config('user.name', 'Scott Chacon') # sets value + #g.config('user.email', 'email@email.com') # sets value + #g.config('user.name') # returns 'Scott Chacon' + #g.config # returns whole config hash + def config(name = nil, value = nil) + if(name && value) + # set value + elsif (name) + # return value + lib.config_get(name) + else + # return hash + lib.config_list + end + end + # factory methods def object(objectish) @@ -75,6 +106,10 @@ module Git self.object('HEAD').grep(string) end + def diff(objectish = 'HEAD', obj2 = nil) + Git::Diff.new(self, objectish, obj2) + end + # convenience methods def revparse(objectish) -- cgit