3 class GitTagNameDoesNotExist< StandardError
6 # represents a git object
10 attr_accessor :sha, :size, :type, :mode
14 def initialize(base, sha)
17 @size = @base.lib.object_size(@sha)
22 @base.lib.object_contents(@sha)
26 self.contents.split("\n")
30 raise NotImplementedError
37 def grep(string, path_limiter = nil, opts = {})
38 default = {:object => @sha, :path_limiter => path_limiter}
39 grep_options = default.merge(opts)
40 @base.lib.grep(string, grep_options)
44 Git::Diff.new(@base, @sha, objectish)
48 Git::Log.new(@base, count).object(@sha)
54 class Blob < AbstractObject
56 def initialize(base, sha, mode = nil)
68 class Tree < AbstractObject
73 def initialize(base, sha, mode = nil)
86 alias_method :files, :blobs
92 alias_method :subtrees, :trees
93 alias_method :subdirectories, :trees
101 # actually run the git command
106 data = @base.lib.ls_tree(@sha)
107 data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
108 data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
114 class Commit < AbstractObject
129 Tree.new(@base, @tree)
136 # array of all parent commits
161 alias_method :date, :committer_date
173 # see if this object has been initialized and do so if not
176 data = @base.lib.commit_data(@sha)
177 @committer = Git::Author.new(data['committer'])
178 @author = Git::Author.new(data['author'])
179 @tree = Tree.new(@base, data['tree'])
180 @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
181 @message = data['message'].chomp
187 class Tag < AbstractObject
190 def initialize(base, sha, name)
204 # if we're calling this, we don't know what type it is yet
205 # so this is our little factory method
206 def new(base, objectish, is_tag = false)
208 sha = base.lib.tag_sha(objectish)
210 raise Git::GitTagNameDoesNotExist.new(objectish)
212 return Tag.new(base, sha, objectish)
214 sha = base.lib.revparse(objectish)
215 type = base.lib.object_type(sha)
221 when /commit/: Commit
224 klass::new(base, sha)