5 @working_directory = nil
9 # opens a bare Git Repository - no working directory options
10 def self.bare(git_dir)
11 self.new :repository => git_dir
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 git_options = default.merge(opts)
23 # initializes a git repository
29 def self.init(working_dir, opts = {})
30 default = {:working_directory => working_dir,
31 :repository => File.join(working_dir, '.git')}
32 git_options = default.merge(opts)
34 if git_options[:working_directory]
35 # if !working_dir, make it
36 FileUtils.mkdir_p(git_options[:working_directory]) if !File.directory?(git_options[:working_directory])
40 Git::Lib.new(git_options).init
45 # clones a git repository locally
47 # repository - http://repo.or.cz/w/sinatra.git
58 def self.clone(repository, name, opts = {})
60 self.new(Git::Lib.new.clone(repository, name, opts))
63 def initialize(options = {})
64 if working_dir = options[:working_directory]
65 options[:repository] = File.join(working_dir, '.git') if !options[:repository]
66 options[:index] = File.join(working_dir, '.git', 'index') if !options[:index]
69 @working_directory = Git::WorkingDirectory.new(options[:working_directory]) if options[:working_directory]
70 @repository = Git::Repository.new(options[:repository]) if options[:repository]
71 @index = Git::Index.new(options[:index], false) if options[:index]
88 #g.config('user.name', 'Scott Chacon') # sets value
89 #g.config('user.email', 'email@email.com') # sets value
90 #g.config('user.name') # returns 'Scott Chacon'
91 #g.config # returns whole config hash
92 def config(name = nil, value = nil)
95 lib.config_set(name, value)
107 def object(objectish)
108 Git::Object.new(self, objectish)
110 alias_method :gtree, :object
111 alias_method :gcommit, :object
112 alias_method :gblob, :object
116 Git::Log.new(self, count)
120 Git::Status.new(self)
124 Git::Branches.new(self)
127 def branch(branch_name = 'master')
128 Git::Branch.new(self, branch_name)
137 self.object('HEAD').grep(string)
140 def diff(objectish = 'HEAD', obj2 = nil)
141 Git::Diff.new(self, objectish, obj2)
144 # adds files from the working directory to the git repository
149 def remove(path = '.', opts = {})
150 self.lib.remove(path, opts)
153 def reset(commitish = nil, opts = {})
154 self.lib.reset(commitish, opts)
157 def reset_hard(commitish = nil, opts = {})
158 opts = {:hard => true}.merge(opts)
159 self.lib.reset(path, opts)
162 def commit(message, opts = {})
163 self.lib.commit(message, opts)
166 def commit_all(message, opts = {})
167 opts = {:add_all => true}.merge(opts)
168 self.lib.commit(message, opts)
171 def checkout(branch, opts = {})
172 self.lib.checkout(branch, opts)
175 # convenience methods
177 def revparse(objectish)
178 self.lib.revparse(objectish)