diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-12 10:55:39 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-12 10:55:39 -0800 |
commit | 32fbe703605310c91677225442a62ae0869d0892 (patch) | |
tree | 00c2b73a07e1200e097490c1fa7d6b5a77fa2032 /doc/files/EXAMPLES.html | |
parent | 646304a6e7c3b2c442a0a7db995629e7009c3a14 (diff) | |
download | third_party-ruby-git-32fbe703605310c91677225442a62ae0869d0892.tar.gz third_party-ruby-git-32fbe703605310c91677225442a62ae0869d0892.tar.xz third_party-ruby-git-32fbe703605310c91677225442a62ae0869d0892.zip |
added push, changed some docs, merged README and EXAMPLES, fixed the Rake tasks to build a proper gem
Diffstat (limited to 'doc/files/EXAMPLES.html')
-rw-r--r-- | doc/files/EXAMPLES.html | 281 |
1 files changed, 130 insertions, 151 deletions
diff --git a/doc/files/EXAMPLES.html b/doc/files/EXAMPLES.html index ef92243..63163ef 100644 --- a/doc/files/EXAMPLES.html +++ b/doc/files/EXAMPLES.html @@ -56,7 +56,7 @@ </tr> <tr class="top-aligned-row"> <td><strong>Last Update:</strong></td> - <td>Sun Nov 11 17:51:57 PST 2007</td> + <td>Mon Nov 12 10:27:43 PST 2007</td> </tr> </table> </div> @@ -70,169 +70,148 @@ <div id="description"> <p> -require ‘git’ +Here are a bunch of examples of how to use the Ruby/<a +href="../classes/Git.html">Git</a> package. </p> <p> -# needs read permission only -</p> -<p> -g = <a href="../classes/Git.html#M000002">Git.open</a> (working_dir = -’.’) -</p> -<pre> - (git_dir, index_file) -</pre> -<p> -g.index g.index.readable? g.index.writable? g.repo g.dir -</p> -<p> -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’) -</p> -<p> -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 -</p> -<p> -g.gtree(treeish) g.gblob(treeish) g.gcommit(treeish) -</p> -<p> -g.revparse(‘v2.5:Makefile’) -</p> -<p> -g.branches # returns <a href="../classes/Git/Branch.html">Git::Branch</a> -objects g.branches.local g.branches.remote g.branches[:master].gcommit -g.branches[‘origin/master’].gcommit -</p> -<p> -g.grep(‘hello’) # implies HEAD -g.blob(‘v2.5:Makefile’).grep(‘hello’) -g.tag(‘v2.5’).grep(‘hello’, ‘docs/’) -</p> -<p> -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 -</p> -<p> -g.gtree(‘v2.5’).diff(‘v2.6’).each do |file_diff| +First you have to remember to require rubygems if it’s not. Then +include the ‘git’ gem. </p> <pre> - puts file_diff.path - puts file_diff.patch - puts file_diff.blob(:src).contents + require 'rubygems' + gem 'git' </pre> <p> -end -</p> -<p> -g.config(‘user.name’) # returns ‘Scott Chacon’ -g.config # returns whole config hash -</p> -<p> -g.tag # returns array of Git::Tag objects -</p> -<p> -# needs write permission -</p> -<p> -g = <a href="../classes/Git.html#M000003">Git.init</a> +Here are the operations that need read permission only. </p> <pre> - Git.init('project') - Git.init('/home/schacon/proj', - { :git_dir => '/opt/git/proj.git', - :index_file => '/tmp/index'} ) + 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) + + 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> -g = <a href="../classes/Git.html#M000004">Git.clone</a>(URI, :name => -‘name’, :path => ’/tmp/checkout‘ -</p> -<pre> - (git_dir, index_file) -</pre> -<p> -g.config(‘user.name’, ‘Scott Chacon’) -g.config(‘user.email’, ‘email@email.com’) -</p> -<p> -g.add(’.’) g.add([file1, file2]) -</p> -<p> -g.remove(‘file.txt’) g.remove([‘file.txt’, -‘file2.txt’]) -</p> -<p> -g.commit(‘message’) g.commit_all(‘message’) -</p> -<p> -g = <a href="../classes/Git.html#M000004">Git.clone</a>(repo, -‘myrepo’) Dir.chdir(‘myrepo’) do +And here are the operations that will need to write to your git repository. </p> <pre> - new_file('test-file', 'blahblahblah') - g.status.untracked.each do |file| - puts file.blob(:index).contents - end + g = Git.init + Git.init('project') + Git.init('/home/schacon/proj', + { :git_dir => '/opt/git/proj.git', + :index_file => '/tmp/index'} ) + + g = Git.clone(URI, :name => 'name', :path => '/tmp/checkout' + (git_dir, index_file) + + 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') + Dir.chdir('myrepo') 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 </pre> -<p> -end -</p> -<p> -g.reset # defaults to HEAD g.reset_hard(Git::Commit) -</p> -<p> -g.branch(‘new_branch’) # creates new or fetches existing -g.branch(‘new_branch’).checkout -g.branch(‘new_branch’).delete -g.branch(‘existing_branch’).checkout -</p> -<p> -g.checkout(‘new_branch’) -g.checkout(g.branch(‘new_branch’)) -</p> -<p> -g.branch(name).merge(branch2) g.branch(branch2).merge # merges HEAD with -branch2 -</p> -<p> -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]) -</p> -<p> -r = g.add_remote(name, uri) # <a -href="../classes/Git/Remote.html">Git::Remote</a> r = g.add_remote(name, <a -href="../classes/Git/Base.html">Git::Base</a>) # <a -href="../classes/Git/Remote.html">Git::Remote</a> -</p> -<p> -g.remotes # array of Git::Remotes g.remote(name).fetch -g.remote(name).remove g.remote(name).merge g.remote(name).merge(branch) -</p> -<p> -g.fetch g.fetch(g.remotes.first) -</p> -<p> -g.pull g.pull(Git::Repo, <a -href="../classes/Git/Branch.html">Git::Branch</a>) # fetch and a merge -</p> -<p> -g.add_tag(‘tag_name’) # returns Git::Tag -</p> -<p> -g.repack -</p> </div> |