summaryrefslogtreecommitdiffstats
path: root/doc/files/README.html
blob: 69d8471865bba4ebbd732c8025f18e173f44b77d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>File: README</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



  <div id="fileHeader">
    <h1>README</h1>
    <table class="header-table">
    <tr class="top-aligned-row">
      <td><strong>Path:</strong></td>
      <td>README
      </td>
    </tr>
    <tr class="top-aligned-row">
      <td><strong>Last Update:</strong></td>
      <td>Tue Nov 13 08:54:36 PST 2007</td>
    </tr>
    </table>
  </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <h2><a href="../classes/Git.html">Git</a> Library for Ruby</h2>
<p>
Library for using <a href="../classes/Git.html">Git</a> in Ruby.
</p>
<h1>Homepage</h1>
<p>
The Ruby/<a href="../classes/Git.html">Git</a> homepage is currently at :
</p>
<p>
<a
href="http://jointheconversation.org/rubygit">jointheconversation.org/rubygit</a>
</p>
<p>
<a href="../classes/Git.html">Git</a> public hosting of the project source
code is at:
</p>
<p>
<a href="http://repo.or.cz/w/rubygit.git">repo.or.cz/w/rubygit.git</a>
</p>
<h1>Roadmap</h1>
<p>
Right now I&#8217;m forking calls to the &#8216;git&#8217; binary, but
eventually I&#8217;ll replace that with either C bindings to libgit or
libgit-thin, or I&#8217;ll write pure ruby handlers for at least some of
the <a href="../classes/Git.html">Git</a> stuff.
</p>
<h1>Major Objects</h1>
<p>
<a href="../classes/Git/Base.html">Git::Base</a> - this is the object
returned from a <a href="../classes/Git.html#M000002">Git.open</a> or <a
href="../classes/Git.html#M000004">Git.clone</a>. Most major actions are
called from this object.
</p>
<p>
<a href="../classes/Git/Object.html">Git::Object</a> - this is 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.
</p>
<p>
<a href="../classes/Git/Diff.html">Git::Diff</a> - returns from a @git.diff
command. It is an Enumerable that returns <a
href="../classes/Git/Diff.html">Git::Diff</a>:DiffFile objects from which
you can get per file patches and insertion/deletion statistics. You can
also get total statistics from the <a
href="../classes/Git/Diff.html">Git::Diff</a> object directly.
</p>
<p>
<a href="../classes/Git/Status.html">Git::Status</a> - returns from a
@git.status command. It is an Enumerable that returns <a
href="../classes/Git.html">Git</a>:Status::StatusFile objects for each
object in git, which includes files in the working directory, in the index
and in the repository. Similar to running &#8216;git status&#8217; on the
command line to determine untracked and changed files.
</p>
<p>
<a href="../classes/Git/Branches.html">Git::Branches</a> - Enumerable
object that holds <a href="../classes/Git/Branch.html">Git::Branch</a>
objects. You can call .local or .remote on it to filter to just your local
or remote branches.
</p>
<p>
<a href="../classes/Git/Remote.html">Git::Remote</a> - A reference to a
remote repository that is tracked by this repository.
</p>
<p>
<a href="../classes/Git/Log.html">Git::Log</a> - An Enumerable object that
references all the <a
href="../classes/Git/Object/Commit.html">Git::Object::Commit</a> objects
that encompass your log query, which can be constructed through methods on
the <a href="../classes/Git/Log.html">Git::Log</a> object, like:
</p>
<pre>
 @git.log(20).object(&quot;HEAD^&quot;).since(&quot;2 weeks ago&quot;).between('v2.6', 'v2.7').each { |commit| [block] }
</pre>
<h1>Examples</h1>
<p>
Here are a bunch of examples of how to use the Ruby/<a
href="../classes/Git.html">Git</a> package.
</p>
<p>
First you have to remember to require rubygems if it&#8217;s not. Then
include the &#8216;git&#8217; gem.
</p>
<pre>
   require 'rubygems'
   require 'git'
</pre>
<p>
Here are the operations that need read permission only.
</p>
<pre>
   g = Git.open (working_dir = '.')
          (git_dir, index_file)

   g.index
   g.index.readable?
   g.index.writable?
   g.repo
   g.dir

   g.log   # returns array of Git::Commit objects
   g.log.since('2 weeks ago')
   g.log.between('v2.5', 'v2.6')
   g.log.each {|l| puts l.sha }
   g.gblob('v2.5:Makefile').log.since('2 weeks ago')

   g.object('HEAD^').to_s  # git show / git rev-parse
   g.object('HEAD^').contents
   g.object('v2.5:Makefile').size
   g.object('v2.5:Makefile').sha

   g.gtree(treeish)
   g.gblob(treeish)
   g.gcommit(treeish)

   commit = g.gcommit('1cc8667014381')
    commit.gtree
    commit.parent.sha
    commit.parents.size
    commit.author.name
    commit.author.email
    commit.author.date.strftime(&quot;%m-%d-%y&quot;)
    commit.committer.name
    commit.date.strftime(&quot;%m-%d-%y&quot;)
    commit.message

  tree = g.gtree(&quot;HEAD^{tree}&quot;)
    tree.blobs
    tree.subtrees
    tree.children # blobs and subtrees

   g.revparse('v2.5:Makefile')

   g.branches # returns Git::Branch objects
   g.branches.local
   g.branches.remote
   g.branches[:master].gcommit
   g.branches['origin/master'].gcommit

   g.grep('hello')  # implies HEAD
   g.blob('v2.5:Makefile').grep('hello')
   g.tag('v2.5').grep('hello', 'docs/')

   g.diff(commit1, commit2).size
   g.diff(commit1, commit2).stats
   g.gtree('v2.5').diff('v2.6').insertions
   g.diff('gitsearch1', 'v2.5').path('lib/')
   g.diff('gitsearch1', @git.gtree('v2.5'))
   g.diff('gitsearch1', 'v2.5').path('docs/').patch
   g.gtree('v2.5').diff('v2.6').patch

   g.gtree('v2.5').diff('v2.6').each do |file_diff|
     puts file_diff.path
     puts file_diff.patch
     puts file_diff.blob(:src).contents
   end

   g.config('user.name')  # returns 'Scott Chacon'
   g.config # returns whole config hash

   g.tag # returns array of Git::Tag objects
</pre>
<p>
And here are the operations that will need to write to your git repository.
</p>
<pre>
   g = Git.init
     Git.init('project')
     Git.init('/home/schacon/proj',
                 { :git_dir =&gt; '/opt/git/proj.git',
                     :index_file =&gt; '/tmp/index'} )

   g = Git.clone(URI, :name =&gt; 'name', :path =&gt; '/tmp/checkout')
   g.config('user.name', 'Scott Chacon')
   g.config('user.email', 'email@email.com')

   g.add('.')
   g.add([file1, file2])

   g.remove('file.txt')
   g.remove(['file.txt', 'file2.txt'])

   g.commit('message')
   g.commit_all('message')

   g = Git.clone(repo, 'myrepo')
   g.chdir do
    new_file('test-file', 'blahblahblah')
    g.status.changed.each do |file|
     puts file.blob(:index).contents
    end
   end

   g.reset # defaults to HEAD
   g.reset_hard(Git::Commit)

   g.branch('new_branch') # creates new or fetches existing
   g.branch('new_branch').checkout
   g.branch('new_branch').delete
   g.branch('existing_branch').checkout

   g.checkout('new_branch')
   g.checkout(g.branch('new_branch'))

   g.branch(name).merge(branch2)
   g.branch(branch2).merge  # merges HEAD with branch2

   g.branch(name).in_branch(message) { # add files }  # auto-commits
   g.merge('new_branch')
   g.merge('origin/remote_branch')
   g.merge(b.branch('master'))
   g.merge([branch1, branch2])

   r = g.add_remote(name, uri)  # Git::Remote
   r = g.add_remote(name, Git::Base)  # Git::Remote

   g.remotes  # array of Git::Remotes
   g.remote(name).fetch
   g.remote(name).remove
   g.remote(name).merge
   g.remote(name).merge(branch)

   g.fetch
   g.fetch(g.remotes.first)

   g.pull
   g.pull(Git::Repo, Git::Branch) # fetch and a merge

   g.add_tag('tag_name') # returns Git::Tag

   g.repack

   g.push
   g.push(g.remote('name'))
</pre>

    </div>


   </div>


  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>