added branches, more log stuff, better tests, changed the log api a bit
[rubygit.git] / lib / git / base.rb
blob81700656fcb855aa0c18a7c4816b5033f3b02971
1 module Git
2   
3   class Base
5     @working_directory = nil
6     @repository = nil
7     @index = nil
9     # opens a Git Repository - no working directory options
10     def self.repo(git_dir)
11       self.new :repository => git_dir
12     end
13     
14     # opens a new Git Project from a working directory
15     # you can specify non-standard git_dir and index file in the options
16     def self.open(working_dir, opts={})    
17       default = {:working_directory => working_dir,
18                  :repository => File.join(working_dir, '.git'), 
19                  :index => File.join(working_dir, '.git', 'index')}
20       git_options = default.merge(opts)
21       
22       self.new(git_options)
23     end
24     
25     def initialize(options = {})
26       @working_directory = Git::Repository.new(options[:working_directory]) if options[:working_directory]
27       @repository = Git::Repository.new(options[:repository]) if options[:repository]
28       @index = Git::Index.new(options[:index]) if options[:index]
29     end
30   
31     def self.clone
32       raise NotImplementedError
33     end
34   
35     def self.init
36       raise NotImplementedError
37     end
39     
40     def dir
41       @working_directory
42     end
44     def repo
45       @repository
46     end
47     
48     def index
49       @index
50     end
51     
52     # factory methods
53     
54     def object(objectish)
55       Git::Object.new(self, objectish)
56     end
57     alias_method :tree, :object
58     alias_method :commit, :object
59     alias_method :blob, :object
60     
61     
62     def log(count = 30)
63       Git::Log.new(self, count)
64     end
65     
66     def branches
67       Git::Branches.new(self)
68     end
69     
70     def lib
71       Git::Lib.new(self)
72     end
73     
74     def grep(string)
75       self.object('HEAD').grep(string)
76     end
77     
78     # convenience methods
79     
80     def revparse(objectish)
81       self.lib.revparse(objectish)
82     end
83     
84   end
85   
86 end