summaryrefslogtreecommitdiffstats
path: root/lib/git
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 /lib/git
parent10045d082117d4ef35da31e1c5a825507b02dd97 (diff)
downloadthird_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.tar.gz
third_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.tar.xz
third_party-ruby-git-ab20a674e50268b6c541949c746d77b16a26d15c.zip
added some branching beginnings
added tests for .size
Diffstat (limited to 'lib/git')
-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
5 files changed, 48 insertions, 4 deletions
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