3 class GitTagNameDoesNotExist< StandardError
6 # represents a git object
10 attr_accessor :objectish, :size, :type, :mode
17 def initialize(base, objectish)
19 @objectish = objectish.to_s
24 @sha || @sha = @base.lib.revparse(@objectish)
28 @size || @size = @base.lib.object_size(@objectish)
31 # caches the contents of this call in memory
33 @contents || @contents = @base.lib.object_contents(@objectish)
37 self.contents.split("\n")
41 raise NotImplementedError
48 def grep(string, path_limiter = nil, opts = {})
49 default = {:object => sha, :path_limiter => path_limiter}
50 grep_options = default.merge(opts)
51 @base.lib.grep(string, grep_options)
55 Git::Diff.new(@base, @objectish, objectish)
59 Git::Log.new(@base, count).object(@objectish)
62 # creates an archive of this object (tree)
63 def archive(file = nil, opts = {})
64 @base.lib.archive(@objectish, file, opts)
86 class Blob < AbstractObject
88 def initialize(base, sha, mode = nil)
100 class Tree < AbstractObject
105 def initialize(base, sha, mode = nil)
111 blobs.merge(subtrees)
118 alias_method :files, :blobs
124 alias_method :subtrees, :trees
125 alias_method :subdirectories, :trees
133 # actually run the git command
138 data = @base.lib.ls_tree(@objectish)
139 data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
140 data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
146 class Commit < AbstractObject
154 def initialize(base, sha, init = nil)
167 @base.lib.namerev(sha)
172 Tree.new(@base, @tree)
179 # array of all parent commits
204 alias_method :date, :committer_date
214 @committer = Git::Author.new(data['committer'])
215 @author = Git::Author.new(data['author'])
216 @tree = Tree.new(@base, data['tree'])
217 @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
218 @message = data['message'].chomp
227 # see if this object has been initialized and do so if not
230 data = @base.lib.commit_data(@objectish)
237 class Tag < AbstractObject
240 def initialize(base, sha, name)
254 # if we're calling this, we don't know what type it is yet
255 # so this is our little factory method
256 def new(base, objectish, type = nil, is_tag = false)
258 sha = base.lib.tag_sha(objectish)
260 raise Git::GitTagNameDoesNotExist.new(objectish)
262 return Tag.new(base, sha, objectish)
265 type = base.lib.object_type(objectish)
272 when /commit/: Commit
275 klass::new(base, objectish)