Class: Git::Base
- Inherits:
-
Object
- Object
- Git::Base
- Defined in:
- lib/git/base.rb
Class Method Summary collapse
-
.bare(git_dir) ⇒ Object
opens a bare Git Repository - no working directory options.
-
.clone(repository, name, opts = {}) ⇒ Object
clones a git repository locally.
-
.init(working_dir, opts = {}) ⇒ Object
initializes a git repository.
-
.open(working_dir, opts = {}) ⇒ Object
opens a new Git Project from a working directory you can specify non-standard git_dir and index file in the options.
Instance Method Summary collapse
-
#add(path = '.') ⇒ Object
adds files from the working directory to the git repository.
- #add_remote(name, url, opts = {}) ⇒ Object
- #add_tag(tag_name) ⇒ Object
- #branch(branch_name = 'master') ⇒ Object
- #branches ⇒ Object
- #chdir ⇒ Object
- #checkout(branch = 'master', opts = {}) ⇒ Object
- #commit(message, opts = {}) ⇒ Object
- #commit_all(message, opts = {}) ⇒ Object
-
#config(name = nil, value = nil) ⇒ Object
g.config(‘user.name’, ‘Scott Chacon’) # sets value g.config(‘user.email’, ‘[email protected]’) # sets value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash.
- #current_branch ⇒ Object
- #diff(objectish = 'HEAD', obj2 = nil) ⇒ Object
- #dir ⇒ Object
- #fetch(remote = 'origin') ⇒ Object
- #grep(string) ⇒ Object
- #index ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #lib ⇒ Object
- #log(count = 30) ⇒ Object
- #merge(branch, message = 'merge') ⇒ Object
-
#object(objectish) ⇒ Object
(also: #gtree, #gcommit, #gblob)
factory methods.
- #pull(remote = 'origin', branch = 'master', message = 'origin pull') ⇒ Object
- #push(remote = 'origin', branch = 'master') ⇒ Object
- #remote(remote_name = 'origin') ⇒ Object
- #remotes ⇒ Object
- #remove(path = '.', opts = {}) ⇒ Object
-
#repack ⇒ Object
convenience methods.
- #repo ⇒ Object
- #repo_size ⇒ Object
- #reset(commitish = nil, opts = {}) ⇒ Object
- #reset_hard(commitish = nil, opts = {}) ⇒ Object
- #revparse(objectish) ⇒ Object
- #status ⇒ Object
- #tag(tag_name) ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/git/base.rb', line 63 def initialize( = {}) if working_dir = [:working_directory] [:repository] = File.join(working_dir, '.git') if ![:repository] [:index] = File.join(working_dir, '.git', 'index') if ![:index] end @working_directory = Git::WorkingDirectory.new([:working_directory]) if [:working_directory] @repository = Git::Repository.new([:repository]) if [:repository] @index = Git::Index.new([:index], false) if [:index] end |
Class Method Details
.bare(git_dir) ⇒ Object
opens a bare Git Repository - no working directory options
10 11 12 |
# File 'lib/git/base.rb', line 10 def self.(git_dir) self.new :repository => git_dir end |
.clone(repository, name, opts = {}) ⇒ Object
clones a git repository locally
repository - http://repo.or.cz/w/sinatra.git
name - sinatra
options:
:repository
:bare
or
:working_directory
:index_file
58 59 60 61 |
# File 'lib/git/base.rb', line 58 def self.clone(repository, name, opts = {}) # run git-clone self.new(Git::Lib.new.clone(repository, name, opts)) end |
.init(working_dir, opts = {}) ⇒ Object
initializes a git repository
options:
:repository
:index_file
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/git/base.rb', line 29 def self.init(working_dir, opts = {}) default = {:working_directory => working_dir, :repository => File.join(working_dir, '.git')} = default.merge(opts) if [:working_directory] # if !working_dir, make it FileUtils.mkdir_p([:working_directory]) if !File.directory?([:working_directory]) end # run git_init there Git::Lib.new().init self.new() end |
.open(working_dir, opts = {}) ⇒ Object
opens a new Git Project from a working directory you can specify non-standard git_dir and index file in the options
16 17 18 19 20 21 |
# File 'lib/git/base.rb', line 16 def self.open(working_dir, opts={}) default = {:working_directory => working_dir} = default.merge(opts) self.new() end |
Instance Method Details
#add(path = '.') ⇒ Object
adds files from the working directory to the git repository
162 163 164 |
# File 'lib/git/base.rb', line 162 def add(path = '.') self.lib.add(path) end |
#add_remote(name, url, opts = {}) ⇒ Object
213 214 215 216 217 218 219 |
# File 'lib/git/base.rb', line 213 def add_remote(name, url, opts = {}) if url.is_a?(Git::Base) url = url.repo.path end self.lib.remote_add(name, url, opts) Git::Remote.new(self, name) end |
#add_tag(tag_name) ⇒ Object
229 230 231 232 |
# File 'lib/git/base.rb', line 229 def add_tag(tag_name) self.lib.tag(tag_name) tag(tag_name) end |
#branch(branch_name = 'master') ⇒ Object
140 141 142 |
# File 'lib/git/base.rb', line 140 def branch(branch_name = 'master') Git::Branch.new(self, branch_name) end |
#branches ⇒ Object
136 137 138 |
# File 'lib/git/base.rb', line 136 def branches Git::Branches.new(self) end |
#chdir ⇒ Object
87 88 89 90 91 |
# File 'lib/git/base.rb', line 87 def chdir Dir.chdir(dir.path) do yield dir.path end end |
#checkout(branch = 'master', opts = {}) ⇒ Object
188 189 190 |
# File 'lib/git/base.rb', line 188 def checkout(branch = 'master', opts = {}) self.lib.checkout(branch, opts) end |
#commit(message, opts = {}) ⇒ Object
179 180 181 |
# File 'lib/git/base.rb', line 179 def commit(, opts = {}) self.lib.commit(, opts) end |
#commit_all(message, opts = {}) ⇒ Object
183 184 185 186 |
# File 'lib/git/base.rb', line 183 def commit_all(, opts = {}) opts = {:add_all => true}.merge(opts) self.lib.commit(, opts) end |
#config(name = nil, value = nil) ⇒ Object
g.config(‘user.name’, ‘Scott Chacon’) # sets value g.config(‘user.email’, ‘[email protected]’) # sets value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/git/base.rb', line 105 def config(name = nil, value = nil) if(name && value) # set value lib.config_set(name, value) elsif (name) # return value lib.config_get(name) else # return hash lib.config_list end end |
#current_branch ⇒ Object
244 245 246 |
# File 'lib/git/base.rb', line 244 def current_branch self.lib.branch_current end |
#diff(objectish = 'HEAD', obj2 = nil) ⇒ Object
157 158 159 |
# File 'lib/git/base.rb', line 157 def diff(objectish = 'HEAD', obj2 = nil) Git::Diff.new(self, objectish, obj2) end |
#dir ⇒ Object
75 76 77 |
# File 'lib/git/base.rb', line 75 def dir @working_directory end |
#fetch(remote = 'origin') ⇒ Object
192 193 194 |
# File 'lib/git/base.rb', line 192 def fetch(remote = 'origin') self.lib.fetch(remote) end |
#grep(string) ⇒ Object
153 154 155 |
# File 'lib/git/base.rb', line 153 def grep(string) self.object('HEAD').grep(string) end |
#index ⇒ Object
83 84 85 |
# File 'lib/git/base.rb', line 83 def index @index end |
#log(count = 30) ⇒ Object
128 129 130 |
# File 'lib/git/base.rb', line 128 def log(count = 30) Git::Log.new(self, count) end |
#merge(branch, message = 'merge') ⇒ Object
200 201 202 |
# File 'lib/git/base.rb', line 200 def merge(branch, = 'merge') self.lib.merge(branch, ) end |
#object(objectish) ⇒ Object Also known as: gtree, gcommit, gblob
factory methods
120 121 122 |
# File 'lib/git/base.rb', line 120 def object(objectish) Git::Object.new(self, objectish) end |
#pull(remote = 'origin', branch = 'master', message = 'origin pull') ⇒ Object
204 205 206 207 |
# File 'lib/git/base.rb', line 204 def pull(remote = 'origin', branch = 'master', = 'origin pull') fetch(remote) merge(branch, ) end |
#push(remote = 'origin', branch = 'master') ⇒ Object
196 197 198 |
# File 'lib/git/base.rb', line 196 def push(remote = 'origin', branch = 'master') self.lib.push(remote, branch) end |
#remote(remote_name = 'origin') ⇒ Object
144 145 146 |
# File 'lib/git/base.rb', line 144 def remote(remote_name = 'origin') Git::Remote.new(self, remote_name) end |
#remotes ⇒ Object
209 210 211 |
# File 'lib/git/base.rb', line 209 def remotes self.lib.remotes.map { |r| Git::Remote.new(self, r) } end |
#remove(path = '.', opts = {}) ⇒ Object
166 167 168 |
# File 'lib/git/base.rb', line 166 def remove(path = '.', opts = {}) self.lib.remove(path, opts) end |
#repack ⇒ Object
convenience methods
236 237 238 |
# File 'lib/git/base.rb', line 236 def repack self.lib.repack end |
#repo ⇒ Object
79 80 81 |
# File 'lib/git/base.rb', line 79 def repo @repository end |
#repo_size ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/git/base.rb', line 93 def repo_size size = 0 Dir.chdir(repo.path) do (size, dot) = `du -d0`.chomp.split end size.to_i end |
#reset(commitish = nil, opts = {}) ⇒ Object
170 171 172 |
# File 'lib/git/base.rb', line 170 def reset(commitish = nil, opts = {}) self.lib.reset(commitish, opts) end |
#reset_hard(commitish = nil, opts = {}) ⇒ Object
174 175 176 177 |
# File 'lib/git/base.rb', line 174 def reset_hard(commitish = nil, opts = {}) opts = {:hard => true}.merge(opts) self.lib.reset(commitish, opts) end |
#revparse(objectish) ⇒ Object
240 241 242 |
# File 'lib/git/base.rb', line 240 def revparse(objectish) self.lib.revparse(objectish) end |
#status ⇒ Object
132 133 134 |
# File 'lib/git/base.rb', line 132 def status Git::Status.new(self) end |
#tag(tag_name) ⇒ Object
225 226 227 |
# File 'lib/git/base.rb', line 225 def tag(tag_name) Git::Object.new(self, tag_name, true) end |
#tags ⇒ Object
221 222 223 |
# File 'lib/git/base.rb', line 221 def self.lib..map { |r| tag(r) } end |