blackwinter-git 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README ADDED
@@ -0,0 +1,240 @@
1
+ == Git Library for Ruby
2
+
3
+ Library for using Git in Ruby. Test.
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
+ = Major Objects
18
+
19
+ Git::Base - this is the object returned from a Git.open or Git.clone.
20
+ Most major actions are called from this object.
21
+
22
+ Git::Object - this is the base object for your tree, blob and commit objects,
23
+ returned from @git.gtree or @git.object calls. the Git::AbstractObject will
24
+ have most of the calls in common for all those objects.
25
+
26
+ Git::Diff - returns from a @git.diff command. It is an Enumerable that returns
27
+ Git::Diff:DiffFile objects from which you can get per file patches and insertion/deletion
28
+ statistics. You can also get total statistics from the Git::Diff object directly.
29
+
30
+ Git::Status - returns from a @git.status command. It is an Enumerable that returns
31
+ Git:Status::StatusFile objects for each object in git, which includes files in the working
32
+ directory, in the index and in the repository. Similar to running 'git status' on the command
33
+ line to determine untracked and changed files.
34
+
35
+ Git::Branches - Enumerable object that holds Git::Branch objects. You can call .local or .remote
36
+ 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
41
+ your log query, which can be constructed through methods on the Git::Log object, 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
+ First you have to remember to require rubygems if it's not. Then include the 'git' gem.
50
+
51
+ require 'rubygems'
52
+ require 'git'
53
+
54
+ Here are the operations that need read permission only.
55
+
56
+ g = Git.open (working_dir, :log => Logger.new(STDOUT))
57
+
58
+ g.index
59
+ g.index.readable?
60
+ g.index.writable?
61
+ g.repo
62
+ g.dir
63
+
64
+ g.log # returns array of Git::Commit objects
65
+ g.log.since('2 weeks ago')
66
+ g.log.between('v2.5', 'v2.6')
67
+ g.log.each {|l| puts l.sha }
68
+ g.gblob('v2.5:Makefile').log.since('2 weeks ago')
69
+
70
+ g.object('HEAD^').to_s # git show / git rev-parse
71
+ g.object('HEAD^').contents
72
+ g.object('v2.5:Makefile').size
73
+ g.object('v2.5:Makefile').sha
74
+
75
+ g.gtree(treeish)
76
+ g.gblob(treeish)
77
+ g.gcommit(treeish)
78
+
79
+
80
+ commit = g.gcommit('1cc8667014381')
81
+ commit.gtree
82
+ commit.parent.sha
83
+ commit.parents.size
84
+ commit.author.name
85
+ commit.author.email
86
+ commit.author.date.strftime("%m-%d-%y")
87
+ commit.committer.name
88
+ commit.date.strftime("%m-%d-%y")
89
+ commit.message
90
+
91
+ tree = g.gtree("HEAD^{tree}")
92
+ tree.blobs
93
+ tree.subtrees
94
+ tree.children # blobs and subtrees
95
+
96
+ g.revparse('v2.5:Makefile')
97
+
98
+ g.branches # returns Git::Branch objects
99
+ g.branches.local
100
+ g.branches.remote
101
+ g.branches[:master].gcommit
102
+ g.branches['origin/master'].gcommit
103
+
104
+ g.grep('hello') # implies HEAD
105
+ g.blob('v2.5:Makefile').grep('hello')
106
+ g.tag('v2.5').grep('hello', 'docs/')
107
+
108
+ g.diff(commit1, commit2).size
109
+ g.diff(commit1, commit2).stats
110
+ g.gtree('v2.5').diff('v2.6').insertions
111
+ g.diff('gitsearch1', 'v2.5').path('lib/')
112
+ g.diff('gitsearch1', @git.gtree('v2.5'))
113
+ g.diff('gitsearch1', 'v2.5').path('docs/').patch
114
+ g.gtree('v2.5').diff('v2.6').patch
115
+
116
+ g.gtree('v2.5').diff('v2.6').each do |file_diff|
117
+ puts file_diff.path
118
+ puts file_diff.patch
119
+ puts file_diff.blob(:src).contents
120
+ end
121
+
122
+ g.config('user.name') # returns 'Scott Chacon'
123
+ g.config # returns whole config hash
124
+
125
+ g.tag # returns array of Git::Tag objects
126
+
127
+
128
+
129
+ And here are the operations that will need to write to your git repository.
130
+
131
+
132
+ g = Git.init
133
+ Git.init('project')
134
+ Git.init('/home/schacon/proj',
135
+ { :git_dir => '/opt/git/proj.git',
136
+ :index_file => '/tmp/index'} )
137
+
138
+ g = Git.clone(URI, :name => 'name', :path => '/tmp/checkout')
139
+ g.config('user.name', 'Scott Chacon')
140
+ g.config('user.email', 'email@email.com')
141
+
142
+ g.add('.')
143
+ g.add([file1, file2])
144
+
145
+ g.remove('file.txt')
146
+ g.remove(['file.txt', 'file2.txt'])
147
+
148
+ g.commit('message')
149
+ g.commit_all('message')
150
+
151
+ g = Git.clone(repo, 'myrepo')
152
+ g.chdir do
153
+ new_file('test-file', 'blahblahblah')
154
+ g.status.changed.each do |file|
155
+ puts file.blob(:index).contents
156
+ end
157
+ end
158
+
159
+ g.reset # defaults to HEAD
160
+ g.reset_hard(Git::Commit)
161
+
162
+ g.branch('new_branch') # creates new or fetches existing
163
+ g.branch('new_branch').checkout
164
+ g.branch('new_branch').delete
165
+ g.branch('existing_branch').checkout
166
+
167
+ g.checkout('new_branch')
168
+ g.checkout(g.branch('new_branch'))
169
+
170
+ g.branch(name).merge(branch2)
171
+ g.branch(branch2).merge # merges HEAD with branch2
172
+
173
+ g.branch(name).in_branch(message) { # add files } # auto-commits
174
+ g.merge('new_branch')
175
+ g.merge('origin/remote_branch')
176
+ g.merge(b.branch('master'))
177
+ g.merge([branch1, branch2])
178
+
179
+ r = g.add_remote(name, uri) # Git::Remote
180
+ r = g.add_remote(name, Git::Base) # Git::Remote
181
+
182
+ g.remotes # array of Git::Remotes
183
+ g.remote(name).fetch
184
+ g.remote(name).remove
185
+ g.remote(name).merge
186
+ g.remote(name).merge(branch)
187
+
188
+ g.fetch
189
+ g.fetch(g.remotes.first)
190
+
191
+ g.pull
192
+ g.pull(Git::Repo, Git::Branch) # fetch and a merge
193
+
194
+ g.add_tag('tag_name') # returns Git::Tag
195
+
196
+ g.repack
197
+
198
+ g.push
199
+ g.push(g.remote('name'))
200
+
201
+
202
+ Some examples of more low-level index and tree operations
203
+
204
+ g.with_temp_index do
205
+
206
+ g.read_tree(tree3) # calls self.index.read_tree
207
+ g.read_tree(tree1, :prefix => 'hi/')
208
+
209
+ c = g.commit_tree('message')
210
+ # or #
211
+ t = g.write_tree
212
+ c = g.commit_tree(t, :message => 'message', :parents => [sha1, sha2])
213
+
214
+ g.branch('branch_name').update_ref(c)
215
+ g.update_ref(branch, c)
216
+
217
+ g.with_temp_working do # new blank working directory
218
+ g.checkout
219
+ g.checkout(another_index)
220
+ g.commit # commits to temp_index
221
+ end
222
+ end
223
+
224
+ g.set_index('/path/to/index')
225
+
226
+
227
+ g.with_index(path) do
228
+ # calls set_index, then switches back after
229
+ end
230
+
231
+ g.with_working(dir) do
232
+ # calls set_working, then switches back after
233
+ end
234
+
235
+ g.with_temp_working(dir) do
236
+ g.checkout_index(:prefix => dir, :path_limiter => path)
237
+ # do file work
238
+ g.commit # commits to index
239
+ end
240
+
data/lib/git/author.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Git
2
+ class Author
3
+ attr_accessor :name, :email, :date
4
+
5
+ def initialize(author_string)
6
+ if m = /(.*?) <(.*?)> (\d+) (.*)/.match(author_string)
7
+ @name = m[1]
8
+ @email = m[2]
9
+ @date = Time.at(m[3].to_i)
10
+ end
11
+ end
12
+
13
+ end
14
+ end