spikegrobstein-git 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7590c2711b2cef331336c3011114e6c417835c4b
4
+ data.tar.gz: ebd90dcb85011261faa017be11aa0cc49daa5fb8
5
+ SHA512:
6
+ metadata.gz: c47ea965b7c796a661f6d4ffb96cb3fe09e7fe128d8936a387e81f8a816843b7b1b4ddf5ff18c404414f644799560734a53e5ae1f06937016809906fdefb200d
7
+ data.tar.gz: 0fff8b6e5928c654130fb881050fd0f34e70ab81e4c0fb3183606a9b6a6680b994790385717b3d0176e37a54f695f84b713974bb82e27960237cd41f81a6bf83
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 Scott Chacon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,274 @@
1
+ # Git Library for Ruby
2
+
3
+ Library for using Git in Ruby.
4
+
5
+ ## Homepage
6
+
7
+ Git public hosting of the project source code is at:
8
+
9
+ http://github.com/schacon/ruby-git
10
+
11
+ ## Install
12
+
13
+ You can install Ruby/Git like this:
14
+
15
+ $ sudo gem install git
16
+
17
+ ## Code Status
18
+
19
+ * [![Build Status](https://api.travis-ci.org/schacon/ruby-git.png)](https://travis-ci.org/schacon/ruby-git)
20
+ * [![Code Climate](https://codeclimate.com/github/schacon/ruby-git.png)](https://codeclimate.com/github/schacon/ruby-git)
21
+ * [![Gem Version](https://badge.fury.io/rb/git.png)](http://badge.fury.io/rb/git)
22
+ * [![Dependencies](https://gemnasium.com/schacon/ruby-git.png?travis)](https://gemnasium.com/schacon/ruby-git)
23
+
24
+ ## Major Objects
25
+
26
+ **Git::Base** - The object returned from a `Git.open` or `Git.clone`. Most major actions are called from this object.
27
+
28
+ **Git::Object** - The base object for your tree, blob and commit objects, returned from `@git.gtree` or `@git.object` calls. the `Git::AbstractObject` will have most of the calls in common for all those objects.
29
+
30
+ **Git::Diff** - returns from a `@git.diff` command. It is an Enumerable that returns `Git::Diff:DiffFile` objects from which you can get per file patches and insertion/deletion statistics. You can also get total statistics from the Git::Diff object directly.
31
+
32
+ **Git::Status** - returns from a `@git.status` command. It is an Enumerable that returns
33
+ `Git:Status::StatusFile` objects for each object in git, which includes files in the working
34
+ directory, in the index and in the repository. Similar to running 'git status' on the command line to determine untracked and changed files.
35
+
36
+ **Git::Branches** - Enumerable object that holds `Git::Branch objects`. You can call .local or .remote on it to filter to just your local or remote branches.
37
+
38
+ **Git::Remote**- A reference to a remote repository that is tracked by this repository.
39
+
40
+ **Git::Log** - An Enumerable object that references all the `Git::Object::Commit` objects that encompass your log query, which can be constructed through methods on the `Git::Log object`,
41
+ like:
42
+
43
+ `@git.log(20).object("some_file").since("2 weeks ago").between('v2.6', 'v2.7').each { |commit| [block] }`
44
+
45
+ ## Examples
46
+
47
+ Here are a bunch of examples of how to use the Ruby/Git package.
48
+
49
+ Ruby < 1.9 will require rubygems to be loaded.
50
+
51
+ ```ruby
52
+ require 'rubygems'
53
+ ```
54
+
55
+ Require the 'git' gem.
56
+ ```ruby
57
+ require 'git'
58
+ ```
59
+
60
+ This gem will use the first `git` that it finds in your `PATH` (i.e. when you type `git` on the commandline), if you require a specific executable, you can override it by doing something like the following:
61
+
62
+ ```ruby
63
+ Git::Lib.git_binary = '/path/to/git'
64
+ ```
65
+
66
+ Here are the operations that need read permission only.
67
+
68
+ ```ruby
69
+ g = Git.open(working_dir, :log => Logger.new(STDOUT))
70
+
71
+ g.index
72
+ g.index.readable?
73
+ g.index.writable?
74
+ g.repo
75
+ g.dir
76
+
77
+ g.log # returns array of Git::Commit objects
78
+ g.log.since('2 weeks ago')
79
+ g.log.between('v2.5', 'v2.6')
80
+ g.log.each {|l| puts l.sha }
81
+ g.gblob('v2.5:Makefile').log.since('2 weeks ago')
82
+
83
+ g.object('HEAD^').to_s # git show / git rev-parse
84
+ g.object('HEAD^').contents
85
+ g.object('v2.5:Makefile').size
86
+ g.object('v2.5:Makefile').sha
87
+
88
+ g.gtree(treeish)
89
+ g.gblob(treeish)
90
+ g.gcommit(treeish)
91
+
92
+
93
+ commit = g.gcommit('1cc8667014381')
94
+
95
+ commit.gtree
96
+ commit.parent.sha
97
+ commit.parents.size
98
+ commit.author.name
99
+ commit.author.email
100
+ commit.author.date.strftime("%m-%d-%y")
101
+ commit.committer.name
102
+ commit.date.strftime("%m-%d-%y")
103
+ commit.message
104
+
105
+ tree = g.gtree("HEAD^{tree}")
106
+
107
+ tree.blobs
108
+ tree.subtrees
109
+ tree.children # blobs and subtrees
110
+
111
+ g.revparse('v2.5:Makefile')
112
+
113
+ g.branches # returns Git::Branch objects
114
+ g.branches.local
115
+ g.branches.remote
116
+ g.branches[:master].gcommit
117
+ g.branches['origin/master'].gcommit
118
+
119
+ g.grep('hello') # implies HEAD
120
+ g.blob('v2.5:Makefile').grep('hello')
121
+ g.tag('v2.5').grep('hello', 'docs/')
122
+
123
+ g.diff(commit1, commit2).size
124
+ g.diff(commit1, commit2).stats
125
+ g.gtree('v2.5').diff('v2.6').insertions
126
+ g.diff('gitsearch1', 'v2.5').path('lib/')
127
+ g.diff('gitsearch1', @git.gtree('v2.5'))
128
+ g.diff('gitsearch1', 'v2.5').path('docs/').patch
129
+ g.gtree('v2.5').diff('v2.6').patch
130
+
131
+ g.gtree('v2.5').diff('v2.6').each do |file_diff|
132
+ puts file_diff.path
133
+ puts file_diff.patch
134
+ puts file_diff.blob(:src).contents
135
+ end
136
+
137
+ g.config('user.name') # returns 'Scott Chacon'
138
+ g.config # returns whole config hash
139
+
140
+ g.tags # returns array of Git::Tag objects
141
+ ```
142
+
143
+ And here are the operations that will need to write to your git repository.
144
+
145
+ ```ruby
146
+ g = Git.init
147
+ Git.init('project')
148
+ Git.init('/home/schacon/proj',
149
+ { :repository => '/opt/git/proj.git',
150
+ :index => '/tmp/index'} )
151
+
152
+ g = Git.clone(URI, NAME, :path => '/tmp/checkout')
153
+ g.config('user.name', 'Scott Chacon')
154
+ g.config('user.email', 'email@email.com')
155
+
156
+ g.add # git add -- "."
157
+ g.add(:all=>true) # git add --all -- "."
158
+ g.add('file_path') # git add -- "file_path"
159
+ g.add(['file_path_1', 'file_path_2']) # git add -- "file_path_1" "file_path_2"
160
+
161
+
162
+ g.remove('file.txt')
163
+ g.remove(['file.txt', 'file2.txt'])
164
+
165
+ g.commit('message')
166
+ g.commit_all('message')
167
+
168
+ g = Git.clone(repo, 'myrepo')
169
+ g.chdir do
170
+ new_file('test-file', 'blahblahblah')
171
+ g.status.changed.each do |file|
172
+ puts file.blob(:index).contents
173
+ end
174
+ end
175
+
176
+ g.reset # defaults to HEAD
177
+ g.reset_hard(Git::Commit)
178
+
179
+ g.branch('new_branch') # creates new or fetches existing
180
+ g.branch('new_branch').checkout
181
+ g.branch('new_branch').delete
182
+ g.branch('existing_branch').checkout
183
+
184
+ g.checkout('new_branch')
185
+ g.checkout(g.branch('new_branch'))
186
+
187
+ g.branch(name).merge(branch2)
188
+ g.branch(branch2).merge # merges HEAD with branch2
189
+
190
+ g.branch(name).in_branch(message) { # add files } # auto-commits
191
+ g.merge('new_branch')
192
+ g.merge('origin/remote_branch')
193
+ g.merge(g.branch('master'))
194
+ g.merge([branch1, branch2])
195
+
196
+ r = g.add_remote(name, uri) # Git::Remote
197
+ r = g.add_remote(name, Git::Base) # Git::Remote
198
+
199
+ g.remotes # array of Git::Remotes
200
+ g.remote(name).fetch
201
+ g.remote(name).remove
202
+ g.remote(name).merge
203
+ g.remote(name).merge(branch)
204
+
205
+ g.fetch
206
+ g.fetch(g.remotes.first)
207
+
208
+ g.pull
209
+ g.pull(Git::Repo, Git::Branch) # fetch and a merge
210
+
211
+ g.add_tag('tag_name') # returns Git::Tag
212
+ g.add_tag('tag_name', 'object_reference')
213
+ g.add_tag('tag_name', 'object_reference', {:options => 'here'})
214
+ g.add_tag('tag_name', {:options => 'here'})
215
+
216
+ Options:
217
+ :a | :annotate
218
+ :d
219
+ :f
220
+ :m | :message
221
+ :s
222
+
223
+ g.delete_tag('tag_name')
224
+
225
+ g.repack
226
+
227
+ g.push
228
+ g.push(g.remote('name'))
229
+ ```
230
+
231
+ Some examples of more low-level index and tree operations
232
+
233
+ ```ruby
234
+ g.with_temp_index do
235
+
236
+ g.read_tree(tree3) # calls self.index.read_tree
237
+ g.read_tree(tree1, :prefix => 'hi/')
238
+
239
+ c = g.commit_tree('message')
240
+ # or #
241
+ t = g.write_tree
242
+ c = g.commit_tree(t, :message => 'message', :parents => [sha1, sha2])
243
+
244
+ g.branch('branch_name').update_ref(c)
245
+ g.update_ref(branch, c)
246
+
247
+ g.with_temp_working do # new blank working directory
248
+ g.checkout
249
+ g.checkout(another_index)
250
+ g.commit # commits to temp_index
251
+ end
252
+ end
253
+
254
+ g.set_index('/path/to/index')
255
+
256
+
257
+ g.with_index(path) do
258
+ # calls set_index, then switches back after
259
+ end
260
+
261
+ g.with_working(dir) do
262
+ # calls set_working, then switches back after
263
+ end
264
+
265
+ g.with_temp_working(dir) do
266
+ g.checkout_index(:prefix => dir, :path_limiter => path)
267
+ # do file work
268
+ g.commit # commits to index
269
+ end
270
+ ```
271
+
272
+ ## License
273
+
274
+ licensed under MIT License Copyright (c) 2008 Scott Chacon. See LICENSE for further details.
data/lib/git.rb ADDED
@@ -0,0 +1,148 @@
1
+ # Add the directory containing this file to the start of the load path if it
2
+ # isn't there already.
3
+ $:.unshift(File.dirname(__FILE__)) unless
4
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
5
+
6
+ require 'git/author'
7
+ require 'git/base'
8
+ require 'git/branch'
9
+ require 'git/branches'
10
+ require 'git/diff'
11
+ require 'git/index'
12
+ require 'git/lib'
13
+ require 'git/log'
14
+ require 'git/object'
15
+ require 'git/path'
16
+ require 'git/remote'
17
+ require 'git/repository'
18
+ require 'git/status'
19
+ require 'git/stash'
20
+ require 'git/stashes'
21
+ require 'git/working_directory'
22
+
23
+ lib = Git::Lib.new(nil, nil)
24
+ unless lib.meets_required_version?
25
+ $stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
26
+ end
27
+
28
+ # Git/Ruby Library
29
+ #
30
+ # This provides bindings for working with git in complex
31
+ # interactions, including branching and merging, object
32
+ # inspection and manipulation, history, patch generation
33
+ # and more. You should be able to do most fundamental git
34
+ # operations with this library.
35
+ #
36
+ # This module provides the basic functions to open a git
37
+ # reference to work with. You can open a working directory,
38
+ # open a bare repository, initialize a new repo or clone an
39
+ # existing remote repository.
40
+ #
41
+ # Author:: Scott Chacon (mailto:schacon@gmail.com)
42
+ # License:: MIT License
43
+ module Git
44
+
45
+ #g.config('user.name', 'Scott Chacon') # sets value
46
+ #g.config('user.email', 'email@email.com') # sets value
47
+ #g.config('user.name') # returns 'Scott Chacon'
48
+ #g.config # returns whole config hash
49
+ def config(name = nil, value = nil)
50
+ lib = Git::Lib.new
51
+ if(name && value)
52
+ # set value
53
+ lib.config_set(name, value)
54
+ elsif (name)
55
+ # return value
56
+ lib.config_get(name)
57
+ else
58
+ # return hash
59
+ lib.config_list
60
+ end
61
+ end
62
+
63
+ def global_config(name = nil, value = nil)
64
+ self.class.global_config(name, value)
65
+ end
66
+
67
+ # open a bare repository
68
+ #
69
+ # this takes the path to a bare git repo
70
+ # it expects not to be able to use a working directory
71
+ # so you can't checkout stuff, commit things, etc.
72
+ # but you can do most read operations
73
+ def self.bare(git_dir, options = {})
74
+ Base.bare(git_dir, options)
75
+ end
76
+
77
+ # clones a remote repository
78
+ #
79
+ # options
80
+ # :bare => true (does a bare clone)
81
+ # :repository => '/path/to/alt_git_dir'
82
+ # :index => '/path/to/alt_index_file'
83
+ #
84
+ # example
85
+ # Git.clone('git://repo.or.cz/rubygit.git', 'clone.git', :bare => true)
86
+ #
87
+ def self.clone(repository, name, options = {})
88
+ Base.clone(repository, name, options)
89
+ end
90
+
91
+ # Export the current HEAD (or a branch, if <tt>options[:branch]</tt>
92
+ # is specified) into the +name+ directory, then remove all traces of git from the
93
+ # directory.
94
+ #
95
+ # See +clone+ for options. Does not obey the <tt>:remote</tt> option,
96
+ # since the .git info will be deleted anyway; always uses the default
97
+ # remote, 'origin.'
98
+ def self.export(repository, name, options = {})
99
+ options.delete(:remote)
100
+ repo = clone(repository, name, {:depth => 1}.merge(options))
101
+ repo.checkout("origin/#{options[:branch]}") if options[:branch]
102
+ Dir.chdir(repo.dir.to_s) { FileUtils.rm_r '.git' }
103
+ end
104
+
105
+ # Same as g.config, but forces it to be at the global level
106
+ #
107
+ #g.config('user.name', 'Scott Chacon') # sets value
108
+ #g.config('user.email', 'email@email.com') # sets value
109
+ #g.config('user.name') # returns 'Scott Chacon'
110
+ #g.config # returns whole config hash
111
+ def self.global_config(name = nil, value = nil)
112
+ lib = Git::Lib.new(nil, nil)
113
+ if(name && value)
114
+ # set value
115
+ lib.global_config_set(name, value)
116
+ elsif (name)
117
+ # return value
118
+ lib.global_config_get(name)
119
+ else
120
+ # return hash
121
+ lib.global_config_list
122
+ end
123
+ end
124
+
125
+ # initialize a new git repository, defaults to the current working directory
126
+ #
127
+ # options
128
+ # :repository => '/path/to/alt_git_dir'
129
+ # :index => '/path/to/alt_index_file'
130
+ def self.init(working_dir = '.', options = {})
131
+ Base.init(working_dir, options)
132
+ end
133
+
134
+ # open an existing git working directory
135
+ #
136
+ # this will most likely be the most common way to create
137
+ # a git reference, referring to a working directory.
138
+ # if not provided in the options, the library will assume
139
+ # your git_dir and index are in the default place (.git/, .git/index)
140
+ #
141
+ # options
142
+ # :repository => '/path/to/alt_git_dir'
143
+ # :index => '/path/to/alt_index_file'
144
+ def self.open(working_dir, options = {})
145
+ Base.open(working_dir, options)
146
+ end
147
+
148
+ end