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 Dir.chdir(dir.path) do
95 Dir.chdir(repo.path) do
96 (size, dot) = `du -d0`.chomp.split
101 #g.config('user.name', 'Scott Chacon') # sets value
102 #g.config('user.email', 'email@email.com') # sets value
103 #g.config('user.name') # returns 'Scott Chacon'
104 #g.config # returns whole config hash
105 def config(name = nil, value = nil)
108 lib.config_set(name, value)
120 def object(objectish)
121 Git::Object.new(self, objectish)
123 alias_method :gtree, :object
124 alias_method :gcommit, :object
125 alias_method :gblob, :object
129 Git::Log.new(self, count)
133 Git::Status.new(self)
137 Git::Branches.new(self)
140 def branch(branch_name = 'master')
141 Git::Branch.new(self, branch_name)
144 def remote(remote_name = 'origin')
145 Git::Remote.new(self, remote_name)
154 self.object('HEAD').grep(string)
157 def diff(objectish = 'HEAD', obj2 = nil)
158 Git::Diff.new(self, objectish, obj2)
161 # adds files from the working directory to the git repository
166 def remove(path = '.', opts = {})
167 self.lib.remove(path, opts)
170 def reset(commitish = nil, opts = {})
171 self.lib.reset(commitish, opts)
174 def reset_hard(commitish = nil, opts = {})
175 opts = {:hard => true}.merge(opts)
176 self.lib.reset(commitish, opts)
179 def commit(message, opts = {})
180 self.lib.commit(message, opts)
183 def commit_all(message, opts = {})
184 opts = {:add_all => true}.merge(opts)
185 self.lib.commit(message, opts)
188 def checkout(branch, opts = {})
189 self.lib.checkout(branch, opts)
192 def fetch(remote = 'origin')
193 self.lib.fetch(remote)
196 def merge(branch, message = 'merge')
197 self.lib.merge(branch, message)
200 def pull(remote = 'origin', branch = 'master', message = 'origin pull')
202 merge(branch, message)
206 self.lib.remotes.map { |r| Git::Remote.new(self, r) }
209 def add_remote(name, url, opts = {})
210 if url.is_a?(Git::Base)
213 self.lib.remote_add(name, url, opts)
214 Git::Remote.new(self, name)
218 self.lib.tags.map { |r| tag(r) }
222 Git::Object.new(self, tag_name, true)
225 def add_tag(tag_name)
226 self.lib.tag(tag_name)
230 # convenience methods
236 def revparse(objectish)
237 self.lib.revparse(objectish)
241 self.lib.branch_current