summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 18:01:08 -0800
committerscott Chacon <schacon@agadorsparticus.corp.reactrix.com>2007-11-08 18:01:08 -0800
commitab20a674e50268b6c541949c746d77b16a26d15c (patch)
tree23e0f74748d79811e89ca9c63e2db58dedbe4636
parent10045d082117d4ef35da31e1c5a825507b02dd97 (diff)
downloadthird_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.zip
third_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.tar.gz
third_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.tar.xz
added some branching beginnings
added tests for .size
-rw-r--r--README18
-rw-r--r--lib/git.rb3
-rw-r--r--lib/git/base.rb12
-rw-r--r--lib/git/branch.rb11
-rw-r--r--lib/git/branches.rb16
-rw-r--r--lib/git/lib.rb12
-rw-r--r--lib/git/repository.rb1
-rw-r--r--tests/units/test_object.rb26
8 files changed, 75 insertions, 24 deletions
diff --git a/README b/README
index b47fac0..dacfefe 100644
--- a/README
+++ b/README
@@ -42,14 +42,14 @@ g.log.between('v2.5', 'v2.6')
g.log.since('v2.5').file('Makefile')
g.log.each {|l| puts l.sha }
-**********
-
-
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.rev_parse('HEAD^')
-g.rev_parse('v2.5:Makefile') # returns Git::Object
+g.revparse('v2.5:Makefile')
+**********
g.file('flim/ChangeLog').tags.each {|tag,rev| p [tag,rev.to_s]}
g.file('flim/ChangeLog').logs.each { |log| log.sha }
@@ -60,12 +60,10 @@ g.branches.remote
g.status
-g.tag # returns array of Git::Tag objects
-
-
g.grep('hello')
g.grep('hello', Git::Tag)
+
g.ls_files
g.ls_files(:stage => true)
@@ -76,9 +74,7 @@ g.diff("commit1..commit2")
g.diff_tree(Git::Tree, Git::Tree)
-
-c = Git::Commit.new("HEAD^^")
-c = Git::Commit.new("394839")
+g.tag # returns array of Git::Tag objects
# needs write permission
diff --git a/lib/git.rb b/lib/git.rb
index 91c3e0f..634109e 100644
--- a/lib/git.rb
+++ b/lib/git.rb
@@ -15,6 +15,8 @@ require 'git/working_directory'
require 'git/log'
require 'git/object'
+require 'git/branch'
+
=begin
@@ -25,7 +27,6 @@ require 'git/file'
require 'git/sha'
require 'git/diff'
-require 'git/branch'
require 'git/remote'
=end
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 3c10389..d552432 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -59,10 +59,20 @@ module Git
Git::Log.new(self, count)
end
+ def branches
+ Git::Branches.new(self)
+ end
+
def lib
Git::Lib.new(self)
end
-
+
+ # convenience methods
+
+ def revparse(objectish)
+ self.lib.revparse(objectish)
+ end
+
end
end \ No newline at end of file
diff --git a/lib/git/branch.rb b/lib/git/branch.rb
new file mode 100644
index 0000000..8f8953b
--- /dev/null
+++ b/lib/git/branch.rb
@@ -0,0 +1,11 @@
+module Git
+ class Branch < Path
+
+ @base = nil
+
+ def initialize(base, name)
+ @base = base
+ end
+
+ end
+end
diff --git a/lib/git/branches.rb b/lib/git/branches.rb
new file mode 100644
index 0000000..d664d59
--- /dev/null
+++ b/lib/git/branches.rb
@@ -0,0 +1,16 @@
+module Git
+
+ # object that holds all the available branches
+ class Branches
+ include Enumerable
+
+ @base = nil
+ @branches = nil
+
+ def initialize(base)
+ @base = base
+ @branches = @base.lib.branches_all
+ end
+
+ end
+end \ No newline at end of file
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
index 681ba58..c83ecaa 100644
--- a/lib/git/lib.rb
+++ b/lib/git/lib.rb
@@ -18,7 +18,7 @@ module Git
arr_opts << "#{opts[:between][0]}..#{opts[:between][1].to_s}" if (opts[:between] && opts[:between].size == 2)
arr_opts << opts[:file] if opts[:file].is_a? String
- command('log', arr_opts).split("\n").map { |l| Git::Object::Commit.new(@base, l.split.first) }
+ command_lines('log', arr_opts).map { |l| Git::Object::Commit.new(@base, l.split.first) }
end
def revparse(string)
@@ -30,15 +30,23 @@ module Git
end
def object_size(sha)
- command('cat-file', ['-s', sha])
+ command('cat-file', ['-s', sha]).to_i
end
def object_contents(sha)
command('cat-file', ['-p', sha])
end
+
+ def branches_all
+ command_lines('branch', '-a').map { |l| Git::Branch.new(@base, l) }
+ end
private
+ def command_lines(cmd, opts)
+ command(cmd, opts).split("\n")
+ end
+
def command(cmd, opts)
ENV['GIT_DIR'] = @base.repo.path
ENV['GIT_INDEX_FILE'] = @base.index.path
diff --git a/lib/git/repository.rb b/lib/git/repository.rb
index d76dc8b..7e61167 100644
--- a/lib/git/repository.rb
+++ b/lib/git/repository.rb
@@ -1,5 +1,4 @@
module Git
class Repository < Path
-
end
end
diff --git a/tests/units/test_object.rb b/tests/units/test_object.rb
index b535be7..44bfc57 100644
--- a/tests/units/test_object.rb
+++ b/tests/units/test_object.rb
@@ -6,6 +6,10 @@ class TestObject < Test::Unit::TestCase
def setup
set_file_paths
@git = Git.open(@wdir)
+
+ @commit = @git.object('1cc8667014381')
+ @tree = @git.object('1cc8667014381^{tree}')
+ @blob = @git.object('v2.5:example.txt')
end
def test_commit
@@ -28,14 +32,15 @@ class TestObject < Test::Unit::TestCase
end
def test_object_to_s
- o = @git.object('1cc8667014381')
- assert_equal('commit 1cc8667014381e2788a94777532a788307f38d26', o.to_s)
-
- o = @git.object('1cc8667014381^{tree}')
- assert_equal('tree 94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', o.to_s)
-
- o = @git.object('v2.5:example.txt')
- assert_equal('blob ba492c62b6227d7f3507b4dcc6e6d5f13790eabf', o.to_s)
+ assert_equal('commit 1cc8667014381e2788a94777532a788307f38d26', @commit.to_s)
+ assert_equal('tree 94c827875e2cadb8bc8d4cdd900f19aa9e8634c7', @tree.to_s)
+ assert_equal('blob ba492c62b6227d7f3507b4dcc6e6d5f13790eabf', @blob.to_s)
+ end
+
+ def test_object_size
+ assert_equal(265, @commit.size)
+ assert_equal(72, @tree.size)
+ assert_equal(128, @blob.size)
end
def test_tree
@@ -66,4 +71,9 @@ class TestObject < Test::Unit::TestCase
assert_equal('replace with new text', o.contents)
end
+ def test_revparse
+ sha = @git.revparse('v2.6:example.txt')
+ assert_equal('1f09f2edb9c0d9275d15960771b363ca6940fbe3', sha)
+ end
+
end \ No newline at end of file