3 class GitTagNameDoesNotExist< StandardError
6 # represents a git object
10 attr_accessor :sha, :size, :type, :mode
15 def initialize(base, sha)
18 @size = @base.lib.object_size(@sha)
22 # caches the contents of this call in memory
24 @contents || @contents = @base.lib.object_contents(@sha)
28 self.contents.split("\n")
32 raise NotImplementedError
39 def grep(string, path_limiter = nil, opts = {})
40 default = {:object => @sha, :path_limiter => path_limiter}
41 grep_options = default.merge(opts)
42 @base.lib.grep(string, grep_options)
46 Git::Diff.new(@base, @sha, objectish)
50 Git::Log.new(@base, count).object(@sha)
53 # creates an archive of this object (tree)
54 def archive(file = nil, opts = {})
55 @base.lib.archive(@sha, file, opts)
77 class Blob < AbstractObject
79 def initialize(base, sha, mode = nil)
91 class Tree < AbstractObject
96 def initialize(base, sha, mode = nil)
102 blobs.merge(subtrees)
109 alias_method :files, :blobs
115 alias_method :subtrees, :trees
116 alias_method :subdirectories, :trees
124 # actually run the git command
129 data = @base.lib.ls_tree(@sha)
130 data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
131 data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
137 class Commit < AbstractObject
151 @base.lib.namerev(@sha)
156 Tree.new(@base, @tree)
163 # array of all parent commits
188 alias_method :date, :committer_date
200 # see if this object has been initialized and do so if not
203 data = @base.lib.commit_data(@sha)
204 @committer = Git::Author.new(data['committer'])
205 @author = Git::Author.new(data['author'])
206 @tree = Tree.new(@base, data['tree'])
207 @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
208 @message = data['message'].chomp
214 class Tag < AbstractObject
217 def initialize(base, sha, name)
231 # if we're calling this, we don't know what type it is yet
232 # so this is our little factory method
233 def new(base, objectish, is_tag = false)
235 sha = base.lib.tag_sha(objectish)
237 raise Git::GitTagNameDoesNotExist.new(objectish)
239 return Tag.new(base, sha, objectish)
241 sha = base.lib.revparse(objectish)
242 type = base.lib.object_type(sha)
248 when /commit/: Commit
251 klass::new(base, sha)