| |   |
| 1 | 1 | module Grit |
| 2 | 2 | |
| 3 | 3 | class Commit |
| 4 | | include Lazy |
| 5 | | |
| 6 | 4 | attr_reader :id |
| 7 | 5 | lazy_reader :parents |
| 8 | 6 | lazy_reader :tree |
| … | … | |
| 33 | 33 | @committed_date = committed_date |
| 34 | 34 | @message = message.join("\n") |
| 35 | 35 | @short_message = message[0] || '' |
| 36 | | |
| 37 | | __baked__ |
| 38 | 36 | end |
| 39 | 37 | |
| 40 | 38 | def id_abbrev |
| … | … | |
| 54 | 54 | # |
| 55 | 55 | # Returns Grit::Commit (unbaked) |
| 56 | 56 | def create_initialize(repo, atts) |
| 57 | | @repo = nil |
| 58 | | @id = nil |
| 59 | | @parents = nil |
| 60 | | @tree = nil |
| 61 | | @author = nil |
| 62 | | @authored_date = nil |
| 63 | | @committer = nil |
| 64 | | @committed_date = nil |
| 65 | | @message = nil |
| 66 | | @short_message = nil |
| 67 | | @__baked__ = nil |
| 68 | | |
| 69 | 57 | @repo = repo |
| 70 | 58 | atts.each do |k, v| |
| 71 | | instance_variable_set("@#{k}".to_sym, v) |
| 59 | instance_variable_set("@#{k}", v) |
| 72 | 60 | end |
| 73 | 61 | self |
| 74 | 62 | end |
| 75 | 63 | |
| 76 | | # Use the id of this instance to populate all of the other fields |
| 77 | | # when any of them are called. |
| 78 | | # |
| 79 | | # Returns nil |
| 80 | | def __bake__ |
| 81 | | temp = self.class.find_all(@repo, @id, {:max_count => 1}).first |
| 82 | | @parents = temp.parents |
| 83 | | @tree = temp.tree |
| 84 | | @author = temp.author |
| 85 | | @authored_date = temp.authored_date |
| 86 | | @committer = temp.committer |
| 87 | | @committed_date = temp.committed_date |
| 88 | | @message = temp.message |
| 89 | | @short_message = temp.short_message |
| 90 | | nil |
| 64 | def lazy_source |
| 65 | self.class.find_all(@repo, @id, {:max_count => 1}).first |
| 91 | 66 | end |
| 92 | 67 | |
| 93 | 68 | # Count the number of commits reachable from this ref |
| … | … | |
| 76 | 76 | |
| 77 | 77 | # Find all commits matching the given criteria. |
| 78 | 78 | # +repo+ is the Repo |
| 79 | | # +ref+ is the ref from which to begin (SHA1 or name) |
| 79 | # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all |
| 80 | 80 | # +options+ is a Hash of optional arguments to git |
| 81 | 81 | # :max_count is the maximum number of commits to fetch |
| 82 | 82 | # :skip is the number of commits to skip |
| … | … | |
| 88 | 88 | default_options = {:pretty => "raw"} |
| 89 | 89 | actual_options = default_options.merge(options) |
| 90 | 90 | |
| 91 | | output = repo.git.rev_list(actual_options, ref) |
| 91 | if ref |
| 92 | output = repo.git.rev_list(actual_options, ref) |
| 93 | else |
| 94 | output = repo.git.rev_list(actual_options.merge(:all => true)) |
| 95 | end |
| 92 | 96 | |
| 93 | 97 | self.list_from_string(repo, output) |
| 94 | 98 | end |
| … | … | |
| 199 | 199 | m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/) |
| 200 | 200 | [Actor.from_string(actor), Time.at(epoch.to_i)] |
| 201 | 201 | end |
| 202 | |
| 203 | def to_hash |
| 204 | { |
| 205 | 'id' => id, |
| 206 | 'parents' => parents.map { |p| { 'id' => p.id } }, |
| 207 | 'tree' => tree.id, |
| 208 | 'message' => message, |
| 209 | 'author' => { |
| 210 | 'name' => author.name, |
| 211 | 'email' => author.email |
| 212 | }, |
| 213 | 'committer' => { |
| 214 | 'name' => committer.name, |
| 215 | 'email' => committer.email |
| 216 | }, |
| 217 | 'authored_date' => authored_date.xmlschema, |
| 218 | 'committed_date' => committed_date.xmlschema, |
| 219 | } |
| 220 | end |
| 202 | 221 | end # Commit |
| 203 | 222 | |
| 204 | 223 | end # Grit |
| toggle raw diff |
--- a/vendor/grit/lib/grit/commit.rb
+++ b/vendor/grit/lib/grit/commit.rb
@@ -1,8 +1,6 @@
module Grit
class Commit
- include Lazy
-
attr_reader :id
lazy_reader :parents
lazy_reader :tree
@@ -35,8 +33,6 @@ module Grit
@committed_date = committed_date
@message = message.join("\n")
@short_message = message[0] || ''
-
- __baked__
end
def id_abbrev
@@ -58,40 +54,15 @@ module Grit
#
# Returns Grit::Commit (unbaked)
def create_initialize(repo, atts)
- @repo = nil
- @id = nil
- @parents = nil
- @tree = nil
- @author = nil
- @authored_date = nil
- @committer = nil
- @committed_date = nil
- @message = nil
- @short_message = nil
- @__baked__ = nil
-
@repo = repo
atts.each do |k, v|
- instance_variable_set("@#{k}".to_sym, v)
+ instance_variable_set("@#{k}", v)
end
self
end
- # Use the id of this instance to populate all of the other fields
- # when any of them are called.
- #
- # Returns nil
- def __bake__
- temp = self.class.find_all(@repo, @id, {:max_count => 1}).first
- @parents = temp.parents
- @tree = temp.tree
- @author = temp.author
- @authored_date = temp.authored_date
- @committer = temp.committer
- @committed_date = temp.committed_date
- @message = temp.message
- @short_message = temp.short_message
- nil
+ def lazy_source
+ self.class.find_all(@repo, @id, {:max_count => 1}).first
end
# Count the number of commits reachable from this ref
@@ -105,7 +76,7 @@ module Grit
# Find all commits matching the given criteria.
# +repo+ is the Repo
- # +ref+ is the ref from which to begin (SHA1 or name)
+ # +ref+ is the ref from which to begin (SHA1 or name) or nil for --all
# +options+ is a Hash of optional arguments to git
# :max_count is the maximum number of commits to fetch
# :skip is the number of commits to skip
@@ -117,7 +88,11 @@ module Grit
default_options = {:pretty => "raw"}
actual_options = default_options.merge(options)
- output = repo.git.rev_list(actual_options, ref)
+ if ref
+ output = repo.git.rev_list(actual_options, ref)
+ else
+ output = repo.git.rev_list(actual_options.merge(:all => true))
+ end
self.list_from_string(repo, output)
end
@@ -224,6 +199,25 @@ module Grit
m, actor, epoch = *line.match(/^.+? (.*) (\d+) .*$/)
[Actor.from_string(actor), Time.at(epoch.to_i)]
end
+
+ def to_hash
+ {
+ 'id' => id,
+ 'parents' => parents.map { |p| { 'id' => p.id } },
+ 'tree' => tree.id,
+ 'message' => message,
+ 'author' => {
+ 'name' => author.name,
+ 'email' => author.email
+ },
+ 'committer' => {
+ 'name' => committer.name,
+ 'email' => committer.email
+ },
+ 'authored_date' => authored_date.xmlschema,
+ 'committed_date' => committed_date.xmlschema,
+ }
+ end
end # Commit
end # Grit |
| |   |
| 1 | module Grit |
| 2 | |
| 3 | class Config |
| 4 | def initialize(repo) |
| 5 | @repo = repo |
| 6 | end |
| 7 | |
| 8 | def []=(key, value) |
| 9 | @repo.git.config({}, key, value) |
| 10 | @data = nil |
| 11 | end |
| 12 | |
| 13 | def [](key) |
| 14 | data[key] |
| 15 | end |
| 16 | |
| 17 | def fetch(key, default = nil) |
| 18 | data[key] || default || raise(IndexError.new("key not found")) |
| 19 | end |
| 20 | |
| 21 | def keys |
| 22 | data.keys |
| 23 | end |
| 24 | |
| 25 | protected |
| 26 | def data |
| 27 | @data ||= load_config |
| 28 | end |
| 29 | |
| 30 | def load_config |
| 31 | hash = {} |
| 32 | config_lines.map do |line| |
| 33 | key, value = line.split(/=/, 2) |
| 34 | hash[key] = value |
| 35 | end |
| 36 | hash |
| 37 | end |
| 38 | |
| 39 | def config_lines |
| 40 | @repo.git.config(:list => true).split(/\n/) |
| 41 | end |
| 42 | end # Config |
| 43 | |
| 44 | end # Grit |
| toggle raw diff |
--- /dev/null
+++ b/vendor/grit/lib/grit/config.rb
@@ -0,0 +1,44 @@
+module Grit
+
+ class Config
+ def initialize(repo)
+ @repo = repo
+ end
+
+ def []=(key, value)
+ @repo.git.config({}, key, value)
+ @data = nil
+ end
+
+ def [](key)
+ data[key]
+ end
+
+ def fetch(key, default = nil)
+ data[key] || default || raise(IndexError.new("key not found"))
+ end
+
+ def keys
+ data.keys
+ end
+
+ protected
+ def data
+ @data ||= load_config
+ end
+
+ def load_config
+ hash = {}
+ config_lines.map do |line|
+ key, value = line.split(/=/, 2)
+ hash[key] = value
+ end
+ hash
+ end
+
+ def config_lines
+ @repo.git.config(:list => true).split(/\n/)
+ end
+ end # Config
+
+end # Grit
\ No newline at end of file |
| |   |
| 26 | 26 | diffs = [] |
| 27 | 27 | |
| 28 | 28 | while !lines.empty? |
| 29 | | m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(\S+) b/(\S+)$}) |
| 29 | m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$}) |
| 30 | 30 | |
| 31 | 31 | if lines.first =~ /^old mode/ |
| 32 | 32 | m, a_mode = *lines.shift.match(/^old mode (\d+)/) |
| 33 | 33 | m, b_mode = *lines.shift.match(/^new mode (\d+)/) |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | | if lines.first =~ /^diff --git/ |
| 36 | if lines.empty? || lines.first =~ /^diff --git/ |
| 37 | 37 | diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil) |
| 38 | 38 | next |
| 39 | 39 | end |
| … | … | |
| 67 | 67 | end |
| 68 | 68 | end # Diff |
| 69 | 69 | |
| 70 | | end # Grit |
| 70 | end # Grit |
| toggle raw diff |
--- a/vendor/grit/lib/grit/diff.rb
+++ b/vendor/grit/lib/grit/diff.rb
@@ -26,14 +26,14 @@ module Grit
diffs = []
while !lines.empty?
- m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(\S+) b/(\S+)$})
+ m, a_path, b_path = *lines.shift.match(%r{^diff --git a/(.+?) b/(.+)$})
if lines.first =~ /^old mode/
m, a_mode = *lines.shift.match(/^old mode (\d+)/)
m, b_mode = *lines.shift.match(/^new mode (\d+)/)
end
- if lines.first =~ /^diff --git/
+ if lines.empty? || lines.first =~ /^diff --git/
diffs << Diff.new(repo, a_path, b_path, nil, nil, a_mode, b_mode, false, false, nil)
next
end
@@ -67,4 +67,4 @@ module Grit
end
end # Diff
-end # Grit
\ No newline at end of file
+end # Grit |
| |   |
| 1 | ## |
| 1 | 2 | # Allows attributes to be declared as lazy, meaning that they won't be |
| 2 | | # computed until they are asked for. Just mix this module in: |
| 3 | # computed until they are asked for. |
| 3 | 4 | # |
| 4 | | # class Foo |
| 5 | | # include Lazy |
| 6 | | # ... |
| 7 | | # end |
| 8 | | # |
| 9 | | # To specify a lazy reader: |
| 10 | | # |
| 11 | | # lazy_reader :att |
| 5 | # Works by delegating each lazy_reader to a cached lazy_source method. |
| 12 | 6 | # |
| 13 | | # Then, define a method called __bake__ that computes all your lazy |
| 14 | | # attributes: |
| 7 | # class Person |
| 8 | # lazy_reader :eyes |
| 15 | 9 | # |
| 16 | | # def __bake__ |
| 17 | | # @att = ... |
| 10 | # def lazy_source |
| 11 | # OpenStruct.new(:eyes => 2) |
| 18 | 12 | # end |
| 13 | # end |
| 19 | 14 | # |
| 20 | | # If you happen to have already done all the hard work, you can mark an instance |
| 21 | | # as already baked by calling: |
| 15 | # >> Person.new.eyes |
| 16 | # => 2 |
| 22 | 17 | # |
| 23 | | # __baked__ |
| 24 | | # |
| 25 | | # That's it! (Tom Preston-Werner: rubyisawesome.com) |
| 26 | 18 | module Lazy |
| 27 | | module ClassMethods |
| 28 | | def lazy_reader(*args) |
| 29 | | args.each do |arg| |
| 30 | | define_method(arg) do |
| 31 | | val = instance_variable_get("@#{arg}") |
| 19 | def lazy_reader(*args) |
| 20 | args.each do |arg| |
| 21 | ivar = "@#{arg}" |
| 22 | define_method(arg) do |
| 23 | if instance_variables.include?(ivar) |
| 24 | val = instance_variable_get(ivar) |
| 32 | 25 | return val if val |
| 33 | | self.__prebake__ |
| 34 | | instance_variable_get("@#{arg}") |
| 35 | 26 | end |
| 27 | instance_variable_set(ivar, (@lazy_source ||= lazy_source).send(arg)) |
| 36 | 28 | end |
| 37 | 29 | end |
| 38 | 30 | end |
| 39 | | |
| 40 | | def __prebake__ |
| 41 | | return if @__baked__ |
| 42 | | self.__bake__ |
| 43 | | @__baked__ = true |
| 44 | | end |
| 45 | | |
| 46 | | def __baked__ |
| 47 | | @__baked__ = true |
| 48 | | end |
| 49 | | |
| 50 | | def self.included(base) |
| 51 | | base.extend(ClassMethods) |
| 52 | | end |
| 53 | | end |
| 31 | end |
| 32 | |
| 33 | Object.extend Lazy unless Object.ancestors.include? Lazy |
| toggle raw diff |
--- a/vendor/grit/lib/grit/lazy.rb
+++ b/vendor/grit/lib/grit/lazy.rb
@@ -1,53 +1,33 @@
+##
# Allows attributes to be declared as lazy, meaning that they won't be
-# computed until they are asked for. Just mix this module in:
+# computed until they are asked for.
#
-# class Foo
-# include Lazy
-# ...
-# end
-#
-# To specify a lazy reader:
-#
-# lazy_reader :att
+# Works by delegating each lazy_reader to a cached lazy_source method.
#
-# Then, define a method called __bake__ that computes all your lazy
-# attributes:
+# class Person
+# lazy_reader :eyes
#
-# def __bake__
-# @att = ...
+# def lazy_source
+# OpenStruct.new(:eyes => 2)
# end
+# end
#
-# If you happen to have already done all the hard work, you can mark an instance
-# as already baked by calling:
+# >> Person.new.eyes
+# => 2
#
-# __baked__
-#
-# That's it! (Tom Preston-Werner: rubyisawesome.com)
module Lazy
- module ClassMethods
- def lazy_reader(*args)
- args.each do |arg|
- define_method(arg) do
- val = instance_variable_get("@#{arg}")
+ def lazy_reader(*args)
+ args.each do |arg|
+ ivar = "@#{arg}"
+ define_method(arg) do
+ if instance_variables.include?(ivar)
+ val = instance_variable_get(ivar)
return val if val
- self.__prebake__
- instance_variable_get("@#{arg}")
end
+ instance_variable_set(ivar, (@lazy_source ||= lazy_source).send(arg))
end
end
end
-
- def __prebake__
- return if @__baked__
- self.__bake__
- @__baked__ = true
- end
-
- def __baked__
- @__baked__ = true
- end
-
- def self.included(base)
- base.extend(ClassMethods)
- end
-end
\ No newline at end of file
+end
+
+Object.extend Lazy unless Object.ancestors.include? Lazy |
| |   |
| 89 | 89 | # Commits are returned in chronological order. |
| 90 | 90 | # +start+ is the branch/commit name (default 'master') |
| 91 | 91 | # +since+ is a string represeting a date/time |
| 92 | # +extra_options+ is a hash of extra options |
| 92 | 93 | # |
| 93 | 94 | # Returns Grit::Commit[] (baked) |
| 94 | | def commits_since(start = 'master', since = '1970-01-01') |
| 95 | | options = {:since => since} |
| 95 | def commits_since(start = 'master', since = '1970-01-01', extra_options = {}) |
| 96 | options = {:since => since}.merge(extra_options) |
| 96 | 97 | |
| 97 | 98 | Commit.find_all(self, start, options) |
| 98 | 99 | end |
| … | … | |
| 254 | 254 | # |
| 255 | 255 | # Returns nothing |
| 256 | 256 | def enable_daemon_serve |
| 257 | | if @bare |
| 258 | | FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE)) |
| 259 | | else |
| 260 | | FileUtils.touch(File.join(self.path, '.git', DAEMON_EXPORT_FILE)) |
| 261 | | end |
| 257 | FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE)) |
| 262 | 258 | end |
| 263 | 259 | |
| 264 | 260 | # Disable git-daemon serving of this repository by ensuring there is no |
| … | … | |
| 262 | 262 | # |
| 263 | 263 | # Returns nothing |
| 264 | 264 | def disable_daemon_serve |
| 265 | | if @bare |
| 266 | | FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE)) |
| 267 | | else |
| 268 | | FileUtils.rm_f(File.join(self.path, '.git', DAEMON_EXPORT_FILE)) |
| 269 | | end |
| 265 | FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE)) |
| 270 | 266 | end |
| 271 | 267 | |
| 272 | 268 | # The list of alternates for this repo |
| … | … | |
| 298 | 298 | end |
| 299 | 299 | end |
| 300 | 300 | |
| 301 | def config |
| 302 | @config ||= Config.new(self) |
| 303 | end |
| 304 | |
| 301 | 305 | # Pretty object inspection |
| 302 | 306 | def inspect |
| 303 | 307 | %Q{#<Grit::Repo "#{@path}">} |
| toggle raw diff |
--- a/vendor/grit/lib/grit/repo.rb
+++ b/vendor/grit/lib/grit/repo.rb
@@ -89,10 +89,11 @@ module Grit
# Commits are returned in chronological order.
# +start+ is the branch/commit name (default 'master')
# +since+ is a string represeting a date/time
+ # +extra_options+ is a hash of extra options
#
# Returns Grit::Commit[] (baked)
- def commits_since(start = 'master', since = '1970-01-01')
- options = {:since => since}
+ def commits_since(start = 'master', since = '1970-01-01', extra_options = {})
+ options = {:since => since}.merge(extra_options)
Commit.find_all(self, start, options)
end
@@ -253,11 +254,7 @@ module Grit
#
# Returns nothing
def enable_daemon_serve
- if @bare
- FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
- else
- FileUtils.touch(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
- end
+ FileUtils.touch(File.join(self.path, DAEMON_EXPORT_FILE))
end
# Disable git-daemon serving of this repository by ensuring there is no
@@ -265,11 +262,7 @@ module Grit
#
# Returns nothing
def disable_daemon_serve
- if @bare
- FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
- else
- FileUtils.rm_f(File.join(self.path, '.git', DAEMON_EXPORT_FILE))
- end
+ FileUtils.rm_f(File.join(self.path, DAEMON_EXPORT_FILE))
end
# The list of alternates for this repo
@@ -305,6 +298,10 @@ module Grit
end
end
+ def config
+ @config ||= Config.new(self)
+ end
+
# Pretty object inspection
def inspect
%Q{#<Grit::Repo "#{@path}">} |
| |   |
| 1 | 1 | module Grit |
| 2 | 2 | |
| 3 | 3 | class Tree |
| 4 | | include Lazy |
| 5 | | |
| 6 | 4 | lazy_reader :contents |
| 7 | 5 | attr_reader :id |
| 8 | 6 | attr_reader :mode |
| 9 | 7 | attr_reader :name |
| 10 | 8 | |
| 11 | | def initialize |
| 12 | | @contents = nil |
| 13 | | @__baked__ = nil |
| 14 | | end |
| 15 | | |
| 16 | 9 | # Construct the contents of the tree |
| 17 | 10 | # +repo+ is the Repo |
| 18 | 11 | # +treeish+ is the reference |
| … | … | |
| 22 | 22 | @repo = repo |
| 23 | 23 | @id = id |
| 24 | 24 | @contents = [] |
| 25 | | @__baked__ = nil |
| 26 | 25 | |
| 27 | 26 | text.split("\n").each do |line| |
| 28 | 27 | @contents << content_from_string(repo, line) |
| 29 | 28 | end |
| 30 | 29 | @contents.compact! |
| 31 | | __baked__ |
| 30 | |
| 32 | 31 | self |
| 33 | 32 | end |
| 34 | 33 | |
| 35 | | def __bake__ |
| 36 | | temp = Tree.construct(@repo, @id, []) |
| 37 | | @contents = temp.contents |
| 34 | def lazy_source |
| 35 | Tree.construct(@repo, @id, []) |
| 38 | 36 | end |
| 39 | 37 | |
| 40 | 38 | # Create an unbaked Tree containing just the specified attributes |
| … | … | |
| 51 | 51 | # Returns Grit::Tree (unbaked) |
| 52 | 52 | def create_initialize(repo, atts) |
| 53 | 53 | @repo = repo |
| 54 | | @contents = nil |
| 55 | | @__baked__ = nil |
| 56 | 54 | |
| 57 | 55 | atts.each do |k, v| |
| 58 | | instance_variable_set("@#{k}".to_sym, v) |
| 56 | instance_variable_set("@#{k}", v) |
| 59 | 57 | end |
| 60 | 58 | self |
| 61 | 59 | end |
| … | … | |
| 100 | 100 | end |
| 101 | 101 | end # Tree |
| 102 | 102 | |
| 103 | | end # Grit |
| 103 | end # Grit |
| toggle raw diff |
--- a/vendor/grit/lib/grit/tree.rb
+++ b/vendor/grit/lib/grit/tree.rb
@@ -1,18 +1,11 @@
module Grit
class Tree
- include Lazy
-
lazy_reader :contents
attr_reader :id
attr_reader :mode
attr_reader :name
- def initialize
- @contents = nil
- @__baked__ = nil
- end
-
# Construct the contents of the tree
# +repo+ is the Repo
# +treeish+ is the reference
@@ -29,19 +22,17 @@ module Grit
@repo = repo
@id = id
@contents = []
- @__baked__ = nil
text.split("\n").each do |line|
@contents << content_from_string(repo, line)
end
@contents.compact!
- __baked__
+
self
end
- def __bake__
- temp = Tree.construct(@repo, @id, [])
- @contents = temp.contents
+ def lazy_source
+ Tree.construct(@repo, @id, [])
end
# Create an unbaked Tree containing just the specified attributes
@@ -60,11 +51,9 @@ module Grit
# Returns Grit::Tree (unbaked)
def create_initialize(repo, atts)
@repo = repo
- @contents = nil
- @__baked__ = nil
atts.each do |k, v|
- instance_variable_set("@#{k}".to_sym, v)
+ instance_variable_set("@#{k}", v)
end
self
end
@@ -111,4 +100,4 @@ module Grit
end
end # Tree
-end # Grit
\ No newline at end of file
+end # Grit |
| |   |
| 172 | 172 | @c = Commit.create(@r, :id => 'abc') |
| 173 | 173 | assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect |
| 174 | 174 | end |
| 175 | |
| 176 | # to_hash |
| 177 | |
| 178 | def test_to_hash |
| 179 | @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017') |
| 180 | |
| 181 | expected = { |
| 182 | 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"], |
| 183 | 'committed_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema, |
| 184 | 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4", |
| 185 | 'authored_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema, |
| 186 | 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"}, |
| 187 | 'message' => "implement Grit#heads", |
| 188 | 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"}, |
| 189 | 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017" |
| 190 | } |
| 191 | |
| 192 | generated_hash = @c.to_hash |
| 193 | expected.keys.each do |exp_key| |
| 194 | assert_equal expected[exp_key], generated_hash[exp_key] |
| 195 | end |
| 196 | end |
| 175 | 197 | end |
| toggle raw diff |
--- a/vendor/grit/test/test_commit.rb
+++ b/vendor/grit/test/test_commit.rb
@@ -172,4 +172,26 @@ class TestCommit < Test::Unit::TestCase
@c = Commit.create(@r, :id => 'abc')
assert_equal %Q{#<Grit::Commit "abc">}, @c.inspect
end
+
+ # to_hash
+
+ def test_to_hash
+ @c = Commit.create(@r, :id => '4c8124ffcf4039d292442eeccabdeca5af5c5017')
+
+ expected = {
+ 'parents' => ['id' => "634396b2f541a9f2d58b00be1a07f0c358b999b3"],
+ 'committed_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
+ 'tree' => "672eca9b7f9e09c22dcb128c283e8c3c8d7697a4",
+ 'authored_date' => Time.parse("2007-10-10T00:06:12-07:00").localtime.xmlschema,
+ 'committer' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
+ 'message' => "implement Grit#heads",
+ 'author' => {'email' => "tom@mojombo.com", 'name' => "Tom Preston-Werner"},
+ 'id' => "4c8124ffcf4039d292442eeccabdeca5af5c5017"
+ }
+
+ generated_hash = @c.to_hash
+ expected.keys.each do |exp_key|
+ assert_equal expected[exp_key], generated_hash[exp_key]
+ end
+ end
end |
| |   |
| 1 | require File.dirname(__FILE__) + '/helper' |
| 2 | |
| 3 | class TestConfig < Test::Unit::TestCase |
| 4 | def setup |
| 5 | @r = Repo.new(GRIT_REPO) |
| 6 | end |
| 7 | |
| 8 | # data |
| 9 | |
| 10 | def test_bracketed_fetch |
| 11 | Git.any_instance.expects(:config).returns(fixture('simple_config')) |
| 12 | |
| 13 | config = @r.config |
| 14 | |
| 15 | assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"] |
| 16 | end |
| 17 | |
| 18 | def test_bracketed_fetch_returns_nil |
| 19 | Git.any_instance.expects(:config).returns(fixture('simple_config')) |
| 20 | |
| 21 | config = @r.config |
| 22 | |
| 23 | assert_equal nil, config["unknown"] |
| 24 | end |
| 25 | |
| 26 | def test_fetch |
| 27 | Git.any_instance.expects(:config).returns(fixture('simple_config')) |
| 28 | |
| 29 | config = @r.config |
| 30 | |
| 31 | assert_equal "false", config.fetch("core.bare") |
| 32 | end |
| 33 | |
| 34 | def test_fetch_with_default |
| 35 | Git.any_instance.expects(:config).returns(fixture('simple_config')) |
| 36 | |
| 37 | config = @r.config |
| 38 | |
| 39 | assert_equal "default", config.fetch("unknown", "default") |
| 40 | end |
| 41 | |
| 42 | def test_fetch_without_default_raises |
| 43 | Git.any_instance.expects(:config).returns(fixture('simple_config')) |
| 44 | |
| 45 | config = @r.config |
| 46 | |
| 47 | assert_raise(IndexError) do |
| 48 | config.fetch("unknown") |
| 49 | end |
| 50 | end |
| 51 | |
| 52 | def test_set_value |
| 53 | Git.any_instance.expects(:config).with({}, 'unknown', 'default') |
| 54 | |
| 55 | config = @r.config |
| 56 | config["unknown"] = "default" |
| 57 | end |
| 58 | end |
| toggle raw diff |
--- /dev/null
+++ b/vendor/grit/test/test_config.rb
@@ -0,0 +1,58 @@
+require File.dirname(__FILE__) + '/helper'
+
+class TestConfig < Test::Unit::TestCase
+ def setup
+ @r = Repo.new(GRIT_REPO)
+ end
+
+ # data
+
+ def test_bracketed_fetch
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
+
+ config = @r.config
+
+ assert_equal "git://github.com/mojombo/grit.git", config["remote.origin.url"]
+ end
+
+ def test_bracketed_fetch_returns_nil
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
+
+ config = @r.config
+
+ assert_equal nil, config["unknown"]
+ end
+
+ def test_fetch
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
+
+ config = @r.config
+
+ assert_equal "false", config.fetch("core.bare")
+ end
+
+ def test_fetch_with_default
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
+
+ config = @r.config
+
+ assert_equal "default", config.fetch("unknown", "default")
+ end
+
+ def test_fetch_without_default_raises
+ Git.any_instance.expects(:config).returns(fixture('simple_config'))
+
+ config = @r.config
+
+ assert_raise(IndexError) do
+ config.fetch("unknown")
+ end
+ end
+
+ def test_set_value
+ Git.any_instance.expects(:config).with({}, 'unknown', 'default')
+
+ config = @r.config
+ config["unknown"] = "default"
+ end
+end |
| |   |
| 11 | 11 | output = fixture('diff_new_mode') |
| 12 | 12 | |
| 13 | 13 | diffs = Diff.list_from_string(@r, output) |
| 14 | | assert_equal 1, diffs.size |
| 14 | assert_equal 2, diffs.size |
| 15 | 15 | assert_equal 10, diffs.first.diff.split("\n").size |
| 16 | assert_equal nil, diffs.last.diff |
| 16 | 17 | end |
| 17 | 18 | end |
| toggle raw diff |
--- a/vendor/grit/test/test_diff.rb
+++ b/vendor/grit/test/test_diff.rb
@@ -11,7 +11,8 @@ class TestDiff < Test::Unit::TestCase
output = fixture('diff_new_mode')
diffs = Diff.list_from_string(@r, output)
- assert_equal 1, diffs.size
+ assert_equal 2, diffs.size
assert_equal 10, diffs.first.diff.split("\n").size
+ assert_equal nil, diffs.last.diff
end
end |
| |   |
| 21 | 21 | assert_equal "\\'foo\\'", @git.e("'foo'") |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | def test_method_missing |
| 25 | assert_match(/^git version [\w\.]*$/, @git.version) |
| 26 | end |
| 27 | |
| 24 | 28 | def test_transform_options |
| 25 | 29 | assert_equal ["-s"], @git.transform_options({:s => true}) |
| 26 | 30 | assert_equal ["-s '5'"], @git.transform_options({:s => 5}) |
| … | … | |
| 51 | 51 | @git.expects(:execute).with("#{@git_bin_base} foo 'bar\\'s'") |
| 52 | 52 | @git.foo({}, "bar's") |
| 53 | 53 | end |
| 54 | | end |
| 54 | end |
| 55 | |
| toggle raw diff |
--- a/vendor/grit/test/test_git.rb
+++ b/vendor/grit/test/test_git.rb
@@ -21,6 +21,10 @@ class TestGit < Test::Unit::TestCase
assert_equal "\\'foo\\'", @git.e("'foo'")
end
+ def test_method_missing
+ assert_match(/^git version [\w\.]*$/, @git.version)
+ end
+
def test_transform_options
assert_equal ["-s"], @git.transform_options({:s => true})
assert_equal ["-s '5'"], @git.transform_options({:s => 5})
@@ -47,4 +51,5 @@ class TestGit < Test::Unit::TestCase
@git.expects(:execute).with("#{@git_bin_base} foo 'bar\\'s'")
@git.foo({}, "bar's")
end
-end
\ No newline at end of file
+end
+ |
| |   |
| 186 | 186 | # enable_daemon_serve |
| 187 | 187 | |
| 188 | 188 | def test_enable_daemon_serve |
| 189 | | FileUtils.expects(:touch).with(File.join(@r.path, '.git', 'git-daemon-export-ok')) |
| 189 | FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok')) |
| 190 | 190 | @r.enable_daemon_serve |
| 191 | 191 | end |
| 192 | 192 | |
| 193 | 193 | # disable_daemon_serve |
| 194 | 194 | |
| 195 | 195 | def test_disable_daemon_serve |
| 196 | | FileUtils.expects(:rm_f).with(File.join(@r.path, '.git', 'git-daemon-export-ok')) |
| 196 | FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok')) |
| 197 | 197 | @r.disable_daemon_serve |
| 198 | 198 | end |
| 199 | 199 | |
| toggle raw diff |
--- a/vendor/grit/test/test_repo.rb
+++ b/vendor/grit/test/test_repo.rb
@@ -186,14 +186,14 @@ class TestRepo < Test::Unit::TestCase
# enable_daemon_serve
def test_enable_daemon_serve
- FileUtils.expects(:touch).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
+ FileUtils.expects(:touch).with(File.join(@r.path, 'git-daemon-export-ok'))
@r.enable_daemon_serve
end
# disable_daemon_serve
def test_disable_daemon_serve
- FileUtils.expects(:rm_f).with(File.join(@r.path, '.git', 'git-daemon-export-ok'))
+ FileUtils.expects(:rm_f).with(File.join(@r.path, 'git-daemon-export-ok'))
@r.disable_daemon_serve
end
|