added some branching beginnings
[rubygit.git] / lib / git / base.rb
blobd5524323d3850aa56d82ed734d2753a38a082f96
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     
58     def log(count = 30)
59       Git::Log.new(self, count)
60     end
61     
62     def branches
63       Git::Branches.new(self)
64     end
65     
66     def lib
67       Git::Lib.new(self)
68     end
69     
70     # convenience methods
71     
72     def revparse(objectish)
73       self.lib.revparse(objectish)
74     end
75     
76   end
77   
78 end