summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/git.rb10
-rw-r--r--lib/git/base.rb9
-rw-r--r--lib/git/commit.rb4
-rw-r--r--lib/git/lib.rb22
-rw-r--r--lib/git/log.rb35
-rw-r--r--lib/git/object.rb16
m---------tests/files/working0
-rw-r--r--tests/files/working/ex_dir/ex.txt0
-rw-r--r--tests/files/working/example.txt63
-rw-r--r--tests/units/test_log.rb26
10 files changed, 181 insertions, 4 deletions
diff --git a/lib/git.rb b/lib/git.rb
index 2e372d0..c8e14ad 100644
--- a/lib/git.rb
+++ b/lib/git.rb
@@ -6,16 +6,19 @@ $:.unshift(File.dirname(__FILE__)) unless
require 'git/base'
require 'git/path'
-#require 'git/lib'
+require 'git/lib'
require 'git/repository'
require 'git/index'
require 'git/working_directory'
-=begin
+require 'git/log'
require 'git/object'
-require 'git/object/commit'
+require 'git/commit'
+
+=begin
+
require 'git/object/blob'
require 'git/object/tree'
require 'git/object/tag'
@@ -24,7 +27,6 @@ require 'git/author'
require 'git/ref'
require 'git/file'
-require 'git/log'
require 'git/sha'
require 'git/diff'
diff --git a/lib/git/base.rb b/lib/git/base.rb
index 6eb3455..c943b86 100644
--- a/lib/git/base.rb
+++ b/lib/git/base.rb
@@ -49,6 +49,15 @@ module Git
@index
end
+
+ def log(count = 30)
+ Git::Log.new(self, count)
+ end
+
+ def lib
+ Git::Lib.new(self)
+ end
+
private
def is_git_dir(dir)
diff --git a/lib/git/commit.rb b/lib/git/commit.rb
new file mode 100644
index 0000000..1cd5d1d
--- /dev/null
+++ b/lib/git/commit.rb
@@ -0,0 +1,4 @@
+module Git
+ class Commit < Git::Object
+ end
+end \ No newline at end of file
diff --git a/lib/git/lib.rb b/lib/git/lib.rb
new file mode 100644
index 0000000..3df049c
--- /dev/null
+++ b/lib/git/lib.rb
@@ -0,0 +1,22 @@
+module Git
+ class Lib
+
+ @base = nil
+
+ def initialize(base)
+ @base = base
+ end
+
+ def log_shas(count)
+ command('log', "-#{count} --pretty=oneline").split("\n").map { |l| Git::Commit.new(l.split.first) }
+ end
+
+ private
+
+ def command(cmd, opts)
+ ENV['GIT_DIR'] = @base.repo.path
+ `git #{cmd} #{opts}`
+ end
+
+ end
+end \ No newline at end of file
diff --git a/lib/git/log.rb b/lib/git/log.rb
new file mode 100644
index 0000000..fab605e
--- /dev/null
+++ b/lib/git/log.rb
@@ -0,0 +1,35 @@
+module Git
+
+ # object that holds the last X commits on given branch
+ class Log
+ include Enumerable
+
+ @base = nil
+ @commits = nil
+
+ def initialize(base, count = 30)
+ @base = base
+ @commits = @base.lib.log_shas(count)
+ end
+
+ def size
+ @commits.size
+ end
+
+ def each
+ @commits.each do |c|
+ yield c
+ end
+ end
+
+ def first
+ @commits.first
+ end
+
+ def to_s
+ self.map { |c| c.sha }.join("\n")
+ end
+
+ end
+
+end \ No newline at end of file
diff --git a/lib/git/object.rb b/lib/git/object.rb
new file mode 100644
index 0000000..0252fdb
--- /dev/null
+++ b/lib/git/object.rb
@@ -0,0 +1,16 @@
+module Git
+ class Object
+ attr_accessor :sha, :type
+
+ def initialize(sha)
+ @sha = sha
+ end
+
+ def cat_file
+ end
+
+ def raw
+ end
+
+ end
+end \ No newline at end of file
diff --git a/tests/files/working b/tests/files/working
deleted file mode 160000
-Subproject 545ffc79786f268524c35e1e05b1770c7c74faf
diff --git a/tests/files/working/ex_dir/ex.txt b/tests/files/working/ex_dir/ex.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/files/working/ex_dir/ex.txt
diff --git a/tests/files/working/example.txt b/tests/files/working/example.txt
new file mode 100644
index 0000000..8a3fb74
--- /dev/null
+++ b/tests/files/working/example.txt
@@ -0,0 +1,63 @@
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
diff --git a/tests/units/test_log.rb b/tests/units/test_log.rb
new file mode 100644
index 0000000..4dd6a2f
--- /dev/null
+++ b/tests/units/test_log.rb
@@ -0,0 +1,26 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class TestInit < Test::Unit::TestCase
+ def setup
+ set_file_paths
+ @git = Git.open(@wdir)
+ end
+
+ def test_get_log_entries
+ log = @git.log
+ assert(log.first.is_a? Git::Commit)
+ end
+
+ def test_get_log_entries
+ assert_equal(30, @git.log.size)
+ assert_equal(50, @git.log(50).size)
+ assert_equal(10, @git.log(10).size)
+ end
+
+ def test_get_log_to_s
+ assert_equal(@git.log.to_s.split("\n").first, @git.log.first.sha)
+ end
+
+end