minad-git 1.1.1

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