From 32fbe703605310c91677225442a62ae0869d0892 Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Mon, 12 Nov 2007 10:55:39 -0800 Subject: added push, changed some docs, merged README and EXAMPLES, fixed the Rake tasks to build a proper gem --- EXAMPLES | 131 ------- README | 142 +++++++- Rakefile | 6 +- doc/classes/Git/Base.html | 526 +++++++++++++++-------------- doc/classes/Git/Branch.html | 122 +++---- doc/classes/Git/Branches.html | 72 ++-- doc/classes/Git/Diff.html | 128 +++---- doc/classes/Git/Diff/DiffFile.html | 24 +- doc/classes/Git/Lib.html | 52 ++- doc/classes/Git/Object.html | 12 +- doc/classes/Git/Object/AbstractObject.html | 96 +++--- doc/classes/Git/Object/Blob.html | 12 +- doc/classes/Git/Object/Commit.html | 12 +- doc/classes/Git/Object/Tag.html | 24 +- doc/classes/Git/Object/Tree.html | 12 +- doc/classes/Git/Path.html | 36 +- doc/classes/Git/Remote.html | 84 ++--- doc/created.rid | 2 +- doc/files/EXAMPLES.html | 281 +++++++-------- doc/files/README.html | 147 +++++++- doc/files/lib/git/base_rb.html | 2 +- doc/files/lib/git/lib_rb.html | 2 +- doc/fr_file_index.html | 1 - doc/fr_method_index.html | 198 +++++------ lib/git/base.rb | 6 +- lib/git/lib.rb | 4 + tests/units/test_remotes.rb | 35 ++ 27 files changed, 1193 insertions(+), 976 deletions(-) delete mode 100644 EXAMPLES diff --git a/EXAMPLES b/EXAMPLES deleted file mode 100644 index c0d32c5..0000000 --- a/EXAMPLES +++ /dev/null @@ -1,131 +0,0 @@ - require 'git' - - # needs read permission only - - 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 - - - - # needs write permission - - - 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.untracked.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 diff --git a/README b/README index 5e80466..4f2e532 100644 --- a/README +++ b/README @@ -1,9 +1,8 @@ == Git Library for Ruby -= What it is - Library for using Git in Ruby. + = Roadmap Right now I'm forking calls to the 'git' binary, @@ -11,6 +10,143 @@ but eventually I'll replace that with either C bindings to libgit or libgit-thin, or I'll write pure ruby handlers for at least some of the Git stuff. -See EXAMPLES file for, well, examples. += Examples + +Here are a bunch of examples of how to use the Ruby/Git package. + +First you have to remember to require rubygems if it's not. Then include the 'git' gem. + + require 'rubygems' + require 'git' + +Here are the operations that need read permission only. + + 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 + + + +And here are the operations that will need to write to your git repository. + + + 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') + 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')) \ No newline at end of file diff --git a/Rakefile b/Rakefile index fd93a28..6cc6eef 100644 --- a/Rakefile +++ b/Rakefile @@ -5,11 +5,11 @@ require 'rake/gempackagetask' spec = Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = "git" - s.version = "1.0.0" + s.version = "1.0.1" s.author = "Scott Chacon" s.email = "schacon@gmail.com" s.summary = "A package for using Git in Ruby code." - s.files = FileList['lib/*.rb', 'test/*'].to_a + s.files = FileList['lib/**/*', 'tests/**/*', 'doc/**/*'].to_a s.require_path = "lib" s.autorequire = "git" s.test_files = Dir.glob('tests/*.rb') @@ -27,7 +27,7 @@ end desc "Regenerate Documentation" task :doc do |t| - system('rdoc lib/ README EXAMPLES --main README --inline-source') + system('rdoc lib/ README --main README --inline-source') end desc "Run Unit Tests" diff --git a/doc/classes/Git/Base.html b/doc/classes/Git/Base.html index 7f4f2c1..2a7fbce 100644 --- a/doc/classes/Git/Base.html +++ b/doc/classes/Git/Base.html @@ -88,47 +88,48 @@

Methods

- add   - add_remote   - add_tag   - bare   - branch   - branches   - chdir   - checkout   - clone   - commit   - commit_all   - config   - current_branch   - diff   - dir   - fetch   - gblob   - gcommit   - grep   - gtree   - index   - init   - lib   - log   - merge   - new   - object   - open   - pull   - remote   - remotes   - remove   - repack   - repo   - repo_size   - reset   - reset_hard   - revparse   - status   - tag   - tags   + add   + add_remote   + add_tag   + bare   + branch   + branches   + chdir   + checkout   + clone   + commit   + commit_all   + config   + current_branch   + diff   + dir   + fetch   + gblob   + gcommit   + grep   + gtree   + index   + init   + lib   + log   + merge   + new   + object   + open   + pull   + push   + remote   + remotes   + remove   + repack   + repo   + repo_size   + reset   + reset_hard   + revparse   + status   + tag   + tags  
@@ -150,11 +151,11 @@

Public Class methods

-
- +
+ @@ -165,8 +166,8 @@ opens a bare Git Repository - no working directory options

[Source]

-
+ onclick="toggleCode('M000077-source');return false;">[Source]

+
 # File lib/git/base.rb, line 10
     def self.bare(git_dir)
@@ -177,11 +178,11 @@ href="Repository.html">Repository - no working directory options
         
-
- +
+ @@ -206,8 +207,8 @@ options: :index_file

[Source]

-
+ onclick="toggleCode('M000080-source');return false;">[Source]

+
 # File lib/git/base.rb, line 58
     def self.clone(repository, name, opts = {})
@@ -219,11 +220,11 @@ options:
         
-
- +
+ @@ -240,8 +241,8 @@ options: :index_file

[Source]

-
+ onclick="toggleCode('M000079-source');return false;">[Source]

+
 # File lib/git/base.rb, line 29
     def self.init(working_dir, opts = {})
@@ -264,19 +265,19 @@ options:
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000081-source');return false;">[Source]

+
 # File lib/git/base.rb, line 63
     def initialize(options = {})
@@ -294,11 +295,11 @@ options:
         
-
- +
+ @@ -309,8 +310,8 @@ opens a new Git Project from a working directory you can specify non-standard git_dir and index file in the options

[Source]

-
+ onclick="toggleCode('M000078-source');return false;">[Source]

+
 # File lib/git/base.rb, line 16
     def self.open(working_dir, opts={})    
@@ -326,11 +327,11 @@ you can specify non-standard git_dir and index file in the options
 
       

Public Instance methods

-
- +
+ @@ -340,8 +341,8 @@ you can specify non-standard git_dir and index file in the options adds files from the working directory to the git repository

[Source]

-
+ onclick="toggleCode('M000100-source');return false;">[Source]

+
 # File lib/git/base.rb, line 162
     def add(path = '.')
@@ -352,21 +353,21 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000112-source');return false;">[Source]

+
-# File lib/git/base.rb, line 209
+# File lib/git/base.rb, line 213
     def add_remote(name, url, opts = {})
       if url.is_a?(Git::Base)
         url = url.repo.path
@@ -379,21 +380,21 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000115-source');return false;">[Source]

+
-# File lib/git/base.rb, line 225
+# File lib/git/base.rb, line 229
     def add_tag(tag_name)
       self.lib.tag(tag_name)
       tag(tag_name)
@@ -403,19 +404,19 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000095-source');return false;">[Source]

+
 # File lib/git/base.rb, line 140
     def branch(branch_name = 'master')
@@ -426,19 +427,19 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000094-source');return false;">[Source]

+
 # File lib/git/base.rb, line 136
     def branches
@@ -449,19 +450,19 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000085-source');return false;">[Source]

+
 # File lib/git/base.rb, line 87
     def chdir
@@ -474,22 +475,22 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000106-source');return false;">[Source]

+
 # File lib/git/base.rb, line 188
-    def checkout(branch, opts = {})
+    def checkout(branch = 'master', opts = {})
       self.lib.checkout(branch, opts)
     end
 
@@ -497,19 +498,19 @@ adds files from the working directory to the git repository
-
- +
+

[Source]

-
+ onclick="toggleCode('M000104-source');return false;">[Source]

+
 # File lib/git/base.rb, line 179
     def commit(message, opts = {})
@@ -520,19 +521,19 @@ adds files from the working directory to the git repository
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000105-source');return false;">[Source]

+
 # File lib/git/base.rb, line 183
     def commit_all(message, opts = {})
@@ -544,11 +545,11 @@ adds files from the working directory to the git repository
         
-
- +
+ @@ -561,8 +562,8 @@ value g.config(‘user.name’) # returns ‘Scott Chacon’ g.config # returns whole config hash

[Source]

-
+ onclick="toggleCode('M000087-source');return false;">[Source]

+
 # File lib/git/base.rb, line 105
     def config(name = nil, value = nil)
@@ -582,21 +583,21 @@ Chacon’ g.config # returns whole config hash
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000118-source');return false;">[Source]

+
-# File lib/git/base.rb, line 240
+# File lib/git/base.rb, line 244
     def current_branch
       self.lib.branch_current
     end
@@ -605,19 +606,19 @@ Chacon’ g.config # returns whole config hash
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000099-source');return false;">[Source]

+
 # File lib/git/base.rb, line 157
     def diff(objectish = 'HEAD', obj2 = nil)
@@ -628,19 +629,19 @@ Chacon’ g.config # returns whole config hash
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000082-source');return false;">[Source]

+
 # File lib/git/base.rb, line 75
     def dir
@@ -651,19 +652,19 @@ Chacon’ g.config # returns whole config hash
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000107-source');return false;">[Source]

+
 # File lib/git/base.rb, line 192
     def fetch(remote = 'origin')
@@ -674,8 +675,8 @@ Chacon’ g.config # returns whole config hash
         
-
- +
+
gblob(objectish) @@ -683,13 +684,13 @@ Chacon’ g.config # returns whole config hash

-Alias for object +Alias for object

-
- +
+
gcommit(objectish) @@ -697,24 +698,24 @@ Alias for object

-Alias for object +Alias for object

-
- +
+

[Source]

-
+ onclick="toggleCode('M000098-source');return false;">[Source]

+
 # File lib/git/base.rb, line 153
     def grep(string)
@@ -725,8 +726,8 @@ Alias for object
         
-
- +
+
gtree(objectish) @@ -734,24 +735,24 @@ Alias for object

-Alias for object +Alias for object

-
- +
+

[Source]

-
+ onclick="toggleCode('M000084-source');return false;">[Source]

+
 # File lib/git/base.rb, line 83
     def index
@@ -762,19 +763,19 @@ Alias for object
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000097-source');return false;">[Source]

+
 # File lib/git/base.rb, line 149
     def lib
@@ -785,19 +786,19 @@ Alias for object
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000092-source');return false;">[Source]

+
 # File lib/git/base.rb, line 128
     def log(count = 30)
@@ -808,21 +809,21 @@ Alias for object
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000109-source');return false;">[Source]

+
-# File lib/git/base.rb, line 196
+# File lib/git/base.rb, line 200
     def merge(branch, message = 'merge')
       self.lib.merge(branch, message)
     end
@@ -831,11 +832,11 @@ Alias for object
         
-
- +
+ @@ -845,8 +846,8 @@ Alias for object factory methods

[Source]

-
+ onclick="toggleCode('M000088-source');return false;">[Source]

+
 # File lib/git/base.rb, line 120
     def object(objectish)
@@ -857,12 +858,36 @@ factory methods
         
+
+ + + + +
+

[Source]

+
+
+# File lib/git/base.rb, line 204
+    def pull(remote = 'origin', branch = 'master', message = 'origin pull')
+      fetch(remote)
+      merge(branch, message)
+    end
+
+
+
+
+
@@ -871,29 +896,28 @@ factory methods onclick="toggleCode('M000108-source');return false;">[Source]

-# File lib/git/base.rb, line 200
-    def pull(remote = 'origin', branch = 'master', message = 'origin pull')
-      fetch(remote)
-      merge(branch, message)
+# File lib/git/base.rb, line 196
+    def push(remote = 'origin', branch = 'master')
+      self.lib.push(remote, branch)
     end
 
-
- +
+

[Source]

-
+ onclick="toggleCode('M000096-source');return false;">[Source]

+
 # File lib/git/base.rb, line 144
     def remote(remote_name = 'origin')
@@ -904,21 +928,21 @@ factory methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000111-source');return false;">[Source]

+
-# File lib/git/base.rb, line 205
+# File lib/git/base.rb, line 209
     def remotes
       self.lib.remotes.map { |r| Git::Remote.new(self, r) }
     end
@@ -927,19 +951,19 @@ factory methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000101-source');return false;">[Source]

+
 # File lib/git/base.rb, line 166
     def remove(path = '.', opts = {})
@@ -950,11 +974,11 @@ factory methods
         
-
- +
+ @@ -964,10 +988,10 @@ factory methods convenience methods

[Source]

-
+ onclick="toggleCode('M000116-source');return false;">[Source]

+
-# File lib/git/base.rb, line 232
+# File lib/git/base.rb, line 236
     def repack
       self.lib.repack
     end
@@ -976,19 +1000,19 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000083-source');return false;">[Source]

+
 # File lib/git/base.rb, line 79
     def repo
@@ -999,19 +1023,19 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000086-source');return false;">[Source]

+
 # File lib/git/base.rb, line 93
     def repo_size
@@ -1026,19 +1050,19 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000102-source');return false;">[Source]

+
 # File lib/git/base.rb, line 170
     def reset(commitish = nil, opts = {})
@@ -1049,19 +1073,19 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000103-source');return false;">[Source]

+
 # File lib/git/base.rb, line 174
     def reset_hard(commitish = nil, opts = {})
@@ -1073,21 +1097,21 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000117-source');return false;">[Source]

+
-# File lib/git/base.rb, line 236
+# File lib/git/base.rb, line 240
     def revparse(objectish)
       self.lib.revparse(objectish)
     end
@@ -1096,19 +1120,19 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000093-source');return false;">[Source]

+
 # File lib/git/base.rb, line 132
     def status
@@ -1119,21 +1143,21 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000114-source');return false;">[Source]

+
-# File lib/git/base.rb, line 221
+# File lib/git/base.rb, line 225
     def tag(tag_name)
       Git::Object.new(self, tag_name, true)
     end
@@ -1142,21 +1166,21 @@ convenience methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000113-source');return false;">[Source]

+
-# File lib/git/base.rb, line 217
+# File lib/git/base.rb, line 221
     def tags
       self.lib.tags.map { |r| tag(r) }
     end
diff --git a/doc/classes/Git/Branch.html b/doc/classes/Git/Branch.html
index aa97d6b..4fb476d 100644
--- a/doc/classes/Git/Branch.html
+++ b/doc/classes/Git/Branch.html
@@ -88,16 +88,16 @@
       

Methods

- checkout   - create   - current   - delete   - gcommit   - in_branch   - merge   - new   - to_a   - to_s   + checkout   + create   + current   + delete   + gcommit   + in_branch   + merge   + new   + to_a   + to_s  
@@ -142,19 +142,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000067-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 9
     def initialize(base, name)
@@ -177,19 +177,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000069-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 28
     def checkout
@@ -201,19 +201,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000071-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 50
     def create
@@ -224,19 +224,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000073-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 58
     def current
@@ -247,19 +247,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000072-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 54
     def delete
@@ -270,19 +270,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000068-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 23
     def gcommit
@@ -294,11 +294,11 @@
         
-
- +
+ @@ -306,7 +306,7 @@

g.branch(‘new_branch’).in_branch do +href="Branch.html#M000070">in_branch do

   # create new file
@@ -317,8 +317,8 @@ href="Branch.html#M000069">in_branch do
 end
 

[Source]

-
+ onclick="toggleCode('M000070-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 39
     def in_branch (message = 'in branch work')
@@ -336,19 +336,19 @@ end
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000074-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 62
     def merge(branch = nil, message = nil)
@@ -368,19 +368,19 @@ end
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000075-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 75
     def to_a
@@ -391,19 +391,19 @@ end
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000076-source');return false;">[Source]

+
 # File lib/git/branch.rb, line 79
     def to_s
diff --git a/doc/classes/Git/Branches.html b/doc/classes/Git/Branches.html
index 1069f77..c9f9f7e 100644
--- a/doc/classes/Git/Branches.html
+++ b/doc/classes/Git/Branches.html
@@ -94,12 +94,12 @@ object that holds all the available branches
       

Methods

- []   - each   - local   - new   - remote   - size   + []   + each   + local   + new   + remote   + size  
@@ -128,19 +128,19 @@ object that holds all the available branches

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000061-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 10
     def initialize(base)
@@ -159,19 +159,19 @@ object that holds all the available branches
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000066-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 40
     def [](symbol)
@@ -182,19 +182,19 @@ object that holds all the available branches
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000065-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 34
     def each
@@ -207,19 +207,19 @@ object that holds all the available branches
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000062-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 20
     def local
@@ -230,19 +230,19 @@ object that holds all the available branches
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000063-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 24
     def remote
@@ -253,11 +253,11 @@ object that holds all the available branches
         
-
- +
+ @@ -267,8 +267,8 @@ object that holds all the available branches array like methods

[Source]

-
+ onclick="toggleCode('M000064-source');return false;">[Source]

+
 # File lib/git/branches.rb, line 30
     def size
diff --git a/doc/classes/Git/Diff.html b/doc/classes/Git/Diff.html
index a1d441e..a57584c 100644
--- a/doc/classes/Git/Diff.html
+++ b/doc/classes/Git/Diff.html
@@ -94,17 +94,17 @@ object that holds the last X commits on given branch
       

Methods

- []   - deletions   - each   - insertions   - lines   - new   - patch   - path   - size   - stats   - to_s   + []   + deletions   + each   + insertions   + lines   + new   + patch   + path   + size   + stats   + to_s  
@@ -139,19 +139,19 @@ object that holds the last X commits on given branch

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000136-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 16
     def initialize(base, from = nil, to = nil)
@@ -166,11 +166,11 @@ object that holds the last X commits on given branch
 
       

Public Instance methods

-
- +
+ @@ -180,8 +180,8 @@ object that holds the last X commits on given branch enumerable methods

[Source]

-
+ onclick="toggleCode('M000145-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 61
     def [](key)
@@ -193,19 +193,19 @@ enumerable methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000140-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 37
     def deletions
@@ -217,19 +217,19 @@ enumerable methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000146-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 66
     def each
@@ -243,19 +243,19 @@ enumerable methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000141-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 42
     def insertions
@@ -267,19 +267,19 @@ enumerable methods
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000139-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 32
     def lines
@@ -291,11 +291,11 @@ enumerable methods
         
-
- +
+ @@ -305,8 +305,8 @@ enumerable methods if file is provided and is writable, it will write the patch into the file

[Source]

-
+ onclick="toggleCode('M000143-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 53
     def patch(file = nil)
@@ -318,19 +318,19 @@ if file is provided and is writable, it will write the patch into the file
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000137-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 22
     def path(path)
@@ -342,19 +342,19 @@ if file is provided and is writable, it will write the patch into the file
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000138-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 27
     def size
@@ -366,19 +366,19 @@ if file is provided and is writable, it will write the patch into the file
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000142-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 47
     def stats
@@ -390,8 +390,8 @@ if file is provided and is writable, it will write the patch into the file
         
-
- +
+
to_s(file = nil) @@ -399,7 +399,7 @@ if file is provided and is writable, it will write the patch into the file

-Alias for patch +Alias for patch

diff --git a/doc/classes/Git/Diff/DiffFile.html b/doc/classes/Git/Diff/DiffFile.html index ec349f8..f13fd79 100644 --- a/doc/classes/Git/Diff/DiffFile.html +++ b/doc/classes/Git/Diff/DiffFile.html @@ -86,8 +86,8 @@

Methods

- blob   - new   + blob   + new  
@@ -147,19 +147,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000147-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 77
       def initialize(base, hash)
@@ -178,19 +178,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000148-source');return false;">[Source]

+
 # File lib/git/diff.rb, line 87
       def blob(type = :dst)
diff --git a/doc/classes/Git/Lib.html b/doc/classes/Git/Lib.html
index fd3c7b0..bb507b4 100644
--- a/doc/classes/Git/Lib.html
+++ b/doc/classes/Git/Lib.html
@@ -114,15 +114,16 @@
       object_contents  
       object_size  
       object_type  
+      push  
       remote_add  
       remote_remove  
       remotes  
       remove  
-      repack  
+      repack  
       reset  
       revparse  
       tag  
-      tag_sha  
+      tag_sha  
       tags  
       
@@ -895,6 +896,29 @@ READ COMMANDS ##
+
+ + + + +
+

[Source]

+
+
+# File lib/git/lib.rb, line 299
+    def push(remote, branch = 'master')
+      command('push', [remote.to_s, branch.to_s])
+    end
+
+
+
+
+
@@ -1002,21 +1026,21 @@ to get around it some other way later
-
- +
+

[Source]

-
+ onclick="toggleCode('M000060-source');return false;">[Source]

+
-# File lib/git/lib.rb, line 303
+# File lib/git/lib.rb, line 307
     def repack
       command('repack', ['-a', '-d'])
     end
@@ -1097,21 +1121,21 @@ to get around it some other way later
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000059-source');return false;">[Source]

+
-# File lib/git/lib.rb, line 299
+# File lib/git/lib.rb, line 303
     def tag_sha(tag_name)
       command('show-ref',  ['--tags', '-s', tag_name])
     end
diff --git a/doc/classes/Git/Object.html b/doc/classes/Git/Object.html
index 499a044..d6d12f1 100644
--- a/doc/classes/Git/Object.html
+++ b/doc/classes/Git/Object.html
@@ -88,7 +88,7 @@
       

Methods

- new   + new  
@@ -120,11 +120,11 @@ Class Git::Object::Tree

Public Class methods

-
- +
+ @@ -135,8 +135,8 @@ if we’re calling this, we don’t know what type it is yet so this is our little factory method

[Source]

-
+ onclick="toggleCode('M000122-source');return false;">[Source]

+
 # File lib/git/object.rb, line 87
       def new(base, objectish, is_tag = false)
diff --git a/doc/classes/Git/Object/AbstractObject.html b/doc/classes/Git/Object/AbstractObject.html
index e2569c4..10d0080 100644
--- a/doc/classes/Git/Object/AbstractObject.html
+++ b/doc/classes/Git/Object/AbstractObject.html
@@ -86,14 +86,14 @@
       

Methods

- contents   - contents_array   - diff   - grep   - log   - new   - setup   - to_s   + contents   + contents_array   + diff   + grep   + log   + new   + setup   + to_s  
@@ -143,19 +143,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000124-source');return false;">[Source]

+
 # File lib/git/object.rb, line 13
       def initialize(base, sha)
@@ -171,19 +171,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000125-source');return false;">[Source]

+
 # File lib/git/object.rb, line 20
       def contents
@@ -194,19 +194,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000126-source');return false;">[Source]

+
 # File lib/git/object.rb, line 24
       def contents_array
@@ -217,19 +217,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000130-source');return false;">[Source]

+
 # File lib/git/object.rb, line 42
       def diff(objectish)
@@ -240,19 +240,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000129-source');return false;">[Source]

+
 # File lib/git/object.rb, line 36
       def grep(string, path_limiter = nil, opts = {})
@@ -265,19 +265,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000131-source');return false;">[Source]

+
 # File lib/git/object.rb, line 46
       def log(count = 30)
@@ -288,19 +288,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000127-source');return false;">[Source]

+
 # File lib/git/object.rb, line 28
       def setup
@@ -311,19 +311,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000128-source');return false;">[Source]

+
 # File lib/git/object.rb, line 32
       def to_s
diff --git a/doc/classes/Git/Object/Blob.html b/doc/classes/Git/Object/Blob.html
index dd3048d..a3fcb39 100644
--- a/doc/classes/Git/Object/Blob.html
+++ b/doc/classes/Git/Object/Blob.html
@@ -88,7 +88,7 @@
       

Methods

- setup   + setup  
@@ -110,19 +110,19 @@

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000134-source');return false;">[Source]

+
 # File lib/git/object.rb, line 54
       def setup
diff --git a/doc/classes/Git/Object/Commit.html b/doc/classes/Git/Object/Commit.html
index 18d4e1b..2f1e595 100644
--- a/doc/classes/Git/Object/Commit.html
+++ b/doc/classes/Git/Object/Commit.html
@@ -88,7 +88,7 @@
       

Methods

- setup   + setup  
@@ -110,19 +110,19 @@

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000123-source');return false;">[Source]

+
 # File lib/git/object.rb, line 66
       def setup
diff --git a/doc/classes/Git/Object/Tag.html b/doc/classes/Git/Object/Tag.html
index 9055eff..260b4c4 100644
--- a/doc/classes/Git/Object/Tag.html
+++ b/doc/classes/Git/Object/Tag.html
@@ -88,8 +88,8 @@
       

Methods

- new   - setup   + new   + setup  
@@ -124,19 +124,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000132-source');return false;">[Source]

+
 # File lib/git/object.rb, line 74
       def initialize(base, sha, name)
@@ -150,19 +150,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000133-source');return false;">[Source]

+
 # File lib/git/object.rb, line 79
       def setup
diff --git a/doc/classes/Git/Object/Tree.html b/doc/classes/Git/Object/Tree.html
index 9204e5f..4d681e8 100644
--- a/doc/classes/Git/Object/Tree.html
+++ b/doc/classes/Git/Object/Tree.html
@@ -88,7 +88,7 @@
       

Methods

- setup   + setup  
@@ -110,19 +110,19 @@

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000135-source');return false;">[Source]

+
 # File lib/git/object.rb, line 60
       def setup
diff --git a/doc/classes/Git/Path.html b/doc/classes/Git/Path.html
index 0b1f892..16f02af 100644
--- a/doc/classes/Git/Path.html
+++ b/doc/classes/Git/Path.html
@@ -88,9 +88,9 @@
       

Methods

- new   - readable?   - writable?   + new   + readable?   + writable?  
@@ -125,19 +125,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000119-source');return false;">[Source]

+
 # File lib/git/path.rb, line 6
     def initialize(path, check_path = true)
@@ -154,19 +154,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000120-source');return false;">[Source]

+
 # File lib/git/path.rb, line 14
     def readable?
@@ -177,19 +177,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000121-source');return false;">[Source]

+
 # File lib/git/path.rb, line 18
     def writable?
diff --git a/doc/classes/Git/Remote.html b/doc/classes/Git/Remote.html
index fbef922..bf59b38 100644
--- a/doc/classes/Git/Remote.html
+++ b/doc/classes/Git/Remote.html
@@ -88,13 +88,13 @@
       

Methods

- branch   - fetch   - merge   - new   - remove   - remove   - to_s   + branch   + fetch   + merge   + new   + remove   + remove   + to_s  
@@ -139,19 +139,19 @@

Public Class methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000149-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 8
     def initialize(base, name)
@@ -168,19 +168,19 @@
 
       

Public Instance methods

-
- +
+

[Source]

-
+ onclick="toggleCode('M000153-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 29
     def branch(branch = 'master')
@@ -191,19 +191,19 @@
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000151-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 20
     def fetch
@@ -214,11 +214,11 @@
         
-
- +
+ @@ -228,8 +228,8 @@ merge this remote locally

[Source]

-
+ onclick="toggleCode('M000152-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 25
     def merge(branch = 'master')
@@ -240,19 +240,19 @@ merge this remote locally
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000150-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 16
     def remove
@@ -263,19 +263,19 @@ merge this remote locally
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000154-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 33
     def remove
@@ -286,19 +286,19 @@ merge this remote locally
         
-
- +
+

[Source]

-
+ onclick="toggleCode('M000155-source');return false;">[Source]

+
 # File lib/git/remote.rb, line 37
     def to_s
diff --git a/doc/created.rid b/doc/created.rid
index e14a536..3226198 100644
--- a/doc/created.rid
+++ b/doc/created.rid
@@ -1 +1 @@
-Sun Nov 11 17:55:02 PST 2007
+Mon Nov 12 10:52:42 PST 2007
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 @@
     
     
       Last Update:
-      Sun Nov 11 17:51:57 PST 2007
+      Mon Nov 12 10:27:43 PST 2007
     
     
   
@@ -70,169 +70,148 @@

-require ‘git’ +Here are a bunch of examples of how to use the Ruby/Git package.

-# needs read permission only -

-

-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| +First you have to remember to require rubygems if it’s not. Then +include the ‘git’ gem.

-  puts file_diff.path
-  puts file_diff.patch
-  puts file_diff.blob(:src).contents
+   require 'rubygems'
+   gem 'git'
 

-end -

-

-g.config(‘user.name’) # returns ‘Scott Chacon’ -g.config # returns whole config hash -

-

-g.tag # returns array of Git::Tag objects -

-

-# needs write permission -

-

-g = Git.init +Here are the operations that need read permission only.

-  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
 

-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 +And here are the operations that will need to write to your git repository.

- 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
 
-

-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 -

diff --git a/doc/files/README.html b/doc/files/README.html index 3179ce1..12a94d5 100644 --- a/doc/files/README.html +++ b/doc/files/README.html @@ -56,7 +56,7 @@ Last Update: - Sun Nov 11 17:55:00 PST 2007 + Mon Nov 12 10:51:20 PST 2007
@@ -70,7 +70,6 @@

Git Library for Ruby

-

What it is

Library for using Git in Ruby.

@@ -81,9 +80,151 @@ eventually I’ll replace that with either C bindings to libgit or libgit-thin, or I’ll write pure ruby handlers for at least some of the Git stuff.

+

Examples

-See EXAMPLES file for, well, examples. +Here are a bunch of examples of how to use the Ruby/Git package.

+

+First you have to remember to require rubygems if it’s not. Then +include the ‘git’ gem. +

+
+   require 'rubygems'
+   require 'git'
+
+

+Here are the operations that need read permission only. +

+
+   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
+
+

+And here are the operations that will need to write to your git repository. +

+
+   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')
+   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'))
+
diff --git a/doc/files/lib/git/base_rb.html b/doc/files/lib/git/base_rb.html index 4e8dfee..980bf39 100644 --- a/doc/files/lib/git/base_rb.html +++ b/doc/files/lib/git/base_rb.html @@ -56,7 +56,7 @@ Last Update: - Sun Nov 11 16:46:30 PST 2007 + Mon Nov 12 10:49:59 PST 2007
diff --git a/doc/files/lib/git/lib_rb.html b/doc/files/lib/git/lib_rb.html index 7bbabc2..ff92663 100644 --- a/doc/files/lib/git/lib_rb.html +++ b/doc/files/lib/git/lib_rb.html @@ -56,7 +56,7 @@ Last Update: - Sun Nov 11 17:17:50 PST 2007 + Mon Nov 12 10:50:14 PST 2007
diff --git a/doc/fr_file_index.html b/doc/fr_file_index.html index 83c920c..c0e6c49 100644 --- a/doc/fr_file_index.html +++ b/doc/fr_file_index.html @@ -20,7 +20,6 @@

Files

- EXAMPLES
README
lib/git.rb
lib/git/base.rb
diff --git a/doc/fr_method_index.html b/doc/fr_method_index.html index 4a3b21f..9cb8879 100644 --- a/doc/fr_method_index.html +++ b/doc/fr_method_index.html @@ -20,159 +20,161 @@

Methods

- [] (Git::Branches)
+ [] (Git::Branches)
[] (Git::Status)
- [] (Git::Diff)
- add (Git::Base)
+ [] (Git::Diff)
+ add (Git::Base)
add (Git::Lib)
- add_remote (Git::Base)
- add_tag (Git::Base)
+ add_remote (Git::Base)
+ add_tag (Git::Base)
added (Git::Status)
+ bare (Git::Base)
bare (Git)
- bare (Git::Base)
between (Git::Log)
- blob (Git::Diff::DiffFile)
+ blob (Git::Diff::DiffFile)
blob (Git::Status::StatusFile)
- branch (Git::Remote)
- branch (Git::Base)
+ branch (Git::Remote)
+ branch (Git::Base)
branch_current (Git::Lib)
branch_delete (Git::Lib)
branch_new (Git::Lib)
- branches (Git::Base)
+ branches (Git::Base)
branches_all (Git::Lib)
changed (Git::Status)
- chdir (Git::Base)
+ chdir (Git::Base)
+ checkout (Git::Branch)
checkout (Git::Lib)
- checkout (Git::Base)
- checkout (Git::Branch)
- clone (Git::Lib)
+ checkout (Git::Base)
+ clone (Git::Base)
clone (Git)
- clone (Git::Base)
+ clone (Git::Lib)
commit (Git::Lib)
- commit (Git::Base)
- commit_all (Git::Base)
- config (Git::Base)
+ commit (Git::Base)
+ commit_all (Git::Base)
+ config (Git::Base)
config_get (Git::Lib)
config_list (Git::Lib)
config_remote (Git::Lib)
config_set (Git::Lib)
- contents (Git::Object::AbstractObject)
- contents_array (Git::Object::AbstractObject)
- create (Git::Branch)
- current (Git::Branch)
- current_branch (Git::Base)
- delete (Git::Branch)
+ contents (Git::Object::AbstractObject)
+ contents_array (Git::Object::AbstractObject)
+ create (Git::Branch)
+ current (Git::Branch)
+ current_branch (Git::Base)
+ delete (Git::Branch)
deleted (Git::Status)
- deletions (Git::Diff)
- diff (Git::Base)
- diff (Git::Object::AbstractObject)
+ deletions (Git::Diff)
+ diff (Git::Base)
+ diff (Git::Object::AbstractObject)
diff_files (Git::Lib)
diff_full (Git::Lib)
diff_index (Git::Lib)
diff_stats (Git::Lib)
- dir (Git::Base)
- each (Git::Log)
+ dir (Git::Base)
+ each (Git::Diff)
+ each (Git::Branches)
each (Git::Status)
- each (Git::Diff)
- each (Git::Branches)
- fetch (Git::Remote)
+ each (Git::Log)
+ fetch (Git::Remote)
fetch (Git::Lib)
- fetch (Git::Base)
+ fetch (Git::Base)
first (Git::Log)
- gblob (Git::Base)
- gcommit (Git::Branch)
- gcommit (Git::Base)
- grep (Git::Object::AbstractObject)
+ gblob (Git::Base)
+ gcommit (Git::Branch)
+ gcommit (Git::Base)
grep (Git::Lib)
- grep (Git::Base)
- gtree (Git::Base)
- in_branch (Git::Branch)
- index (Git::Base)
+ grep (Git::Object::AbstractObject)
+ grep (Git::Base)
+ gtree (Git::Base)
+ in_branch (Git::Branch)
+ index (Git::Base)
init (Git::Lib)
- init (Git::Base)
init (Git)
- insertions (Git::Diff)
- lib (Git::Base)
- lines (Git::Diff)
- local (Git::Branches)
- log (Git::Base)
- log (Git::Object::AbstractObject)
+ init (Git::Base)
+ insertions (Git::Diff)
+ lib (Git::Base)
+ lines (Git::Diff)
+ local (Git::Branches)
+ log (Git::Object::AbstractObject)
+ log (Git::Base)
log_commits (Git::Lib)
ls_files (Git::Lib)
+ merge (Git::Base)
merge (Git::Lib)
- merge (Git::Branch)
- merge (Git::Remote)
- merge (Git::Base)
- new (Git::Remote)
+ merge (Git::Branch)
+ merge (Git::Remote)
+ new (Git::Object::Tag)
new (Git::Status::StatusFile)
- new (Git::Diff)
- new (Git::Branch)
- new (Git::Diff::DiffFile)
- new (Git::Object::Tag)
- new (Git::Base)
+ new (Git::Branches)
+ new (Git::Diff)
+ new (Git::Base)
new (Git::Log)
- new (Git::Object::AbstractObject)
+ new (Git::Object::AbstractObject)
+ new (Git::Diff::DiffFile)
+ new (Git::Object)
+ new (Git::Branch)
new (Git::Lib)
- new (Git::Object)
new (Git::Status)
- new (Git::Branches)
- new (Git::Path)
+ new (Git::Path)
+ new (Git::Remote)
object (Git::Log)
- object (Git::Base)
+ object (Git::Base)
object_contents (Git::Lib)
object_size (Git::Lib)
object_type (Git::Lib)
open (Git)
- open (Git::Base)
- patch (Git::Diff)
- path (Git::Diff)
+ open (Git::Base)
+ patch (Git::Diff)
+ path (Git::Diff)
path (Git::Log)
pretty (Git::Status)
- pull (Git::Base)
- readable? (Git::Path)
- remote (Git::Branches)
- remote (Git::Base)
+ pull (Git::Base)
+ push (Git::Base)
+ push (Git::Lib)
+ readable? (Git::Path)
+ remote (Git::Branches)
+ remote (Git::Base)
remote_add (Git::Lib)
remote_remove (Git::Lib)
+ remotes (Git::Base)
remotes (Git::Lib)
- remotes (Git::Base)
- remove (Git::Base)
- remove (Git::Remote)
- remove (Git::Remote)
remove (Git::Lib)
- repack (Git::Lib)
- repack (Git::Base)
- repo (Git::Base)
- repo_size (Git::Base)
- reset (Git::Base)
+ remove (Git::Remote)
+ remove (Git::Base)
+ remove (Git::Remote)
+ repack (Git::Lib)
+ repack (Git::Base)
+ repo (Git::Base)
+ repo_size (Git::Base)
+ reset (Git::Base)
reset (Git::Lib)
- reset_hard (Git::Base)
- revparse (Git::Base)
+ reset_hard (Git::Base)
revparse (Git::Lib)
- setup (Git::Object::Blob)
- setup (Git::Object::Tag)
- setup (Git::Object::Commit)
- setup (Git::Object::AbstractObject)
- setup (Git::Object::Tree)
+ revparse (Git::Base)
+ setup (Git::Object::Tag)
+ setup (Git::Object::Commit)
+ setup (Git::Object::Blob)
+ setup (Git::Object::AbstractObject)
+ setup (Git::Object::Tree)
since (Git::Log)
size (Git::Log)
- size (Git::Diff)
- size (Git::Branches)
- stats (Git::Diff)
- status (Git::Base)
- tag (Git::Base)
+ size (Git::Branches)
+ size (Git::Diff)
+ stats (Git::Diff)
+ status (Git::Base)
+ tag (Git::Base)
tag (Git::Lib)
- tag_sha (Git::Lib)
+ tag_sha (Git::Lib)
tags (Git::Lib)
- tags (Git::Base)
- to_a (Git::Branch)
- to_s (Git::Diff)
- to_s (Git::Object::AbstractObject)
- to_s (Git::Branch)
+ tags (Git::Base)
+ to_a (Git::Branch)
+ to_s (Git::Diff)
+ to_s (Git::Branch)
+ to_s (Git::Object::AbstractObject)
to_s (Git::Log)
- to_s (Git::Remote)
+ to_s (Git::Remote)
untracked (Git::Status)
- writable? (Git::Path)
+ writable? (Git::Path)
diff --git a/lib/git/base.rb b/lib/git/base.rb index d97948e..21578f8 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -185,7 +185,7 @@ module Git self.lib.commit(message, opts) end - def checkout(branch, opts = {}) + def checkout(branch = 'master', opts = {}) self.lib.checkout(branch, opts) end @@ -193,6 +193,10 @@ module Git self.lib.fetch(remote) end + def push(remote = 'origin', branch = 'master') + self.lib.push(remote, branch) + end + def merge(branch, message = 'merge') self.lib.merge(branch, message) end diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 5bb2e2b..575f0d7 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -296,6 +296,10 @@ module Git command('fetch', remote.to_s) end + def push(remote, branch = 'master') + command('push', [remote.to_s, branch.to_s]) + end + def tag_sha(tag_name) command('show-ref', ['--tags', '-s', tag_name]) end diff --git a/tests/units/test_remotes.rb b/tests/units/test_remotes.rb index ddb066e..ecf35a4 100644 --- a/tests/units/test_remotes.rb +++ b/tests/units/test_remotes.rb @@ -41,5 +41,40 @@ class TestRemotes < Test::Unit::TestCase #puts loc.remotes.inspect end end + + def test_push + in_temp_dir do |path| + loc = Git.clone(@wbare, 'local') + rem = Git.clone(@wbare, 'remote') + + r = loc.add_remote('testrem', rem) + + loc.chdir do + new_file('test-file1', 'blahblahblah1') + loc.add + loc.commit('master commit') + + loc.branch('testbranch').in_branch('tb commit') do + new_file('test-file3', 'blahblahblah3') + loc.add + true + end + end + assert(!rem.status['test-file1']) + assert(!rem.status['test-file3']) + + loc.push('testrem') + + assert(rem.status['test-file1']) + assert(!rem.status['test-file3']) + + loc.push('testrem', 'testbranch') + + rem.checkout('testbranch') + assert(rem.status['test-file1']) + assert(rem.status['test-file3']) + end + end + end \ No newline at end of file -- cgit