ruby-git-lacravate 0.0.1

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