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)
51 # creates an archive of this object (tree)
52 def archive(file = nil, opts = {})
53 @base.lib.archive(@sha, file, opts)
59 class Blob < AbstractObject
61 def initialize(base, sha, mode = nil)
73 class Tree < AbstractObject
78 def initialize(base, sha, mode = nil)
91 alias_method :files, :blobs
97 alias_method :subtrees, :trees
98 alias_method :subdirectories, :trees
106 # actually run the git command
111 data = @base.lib.ls_tree(@sha)
112 data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) }
113 data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) }
119 class Commit < AbstractObject
133 @base.lib.namerev(@sha)
138 Tree.new(@base, @tree)
145 # array of all parent commits
170 alias_method :date, :committer_date
182 # see if this object has been initialized and do so if not
185 data = @base.lib.commit_data(@sha)
186 @committer = Git::Author.new(data['committer'])
187 @author = Git::Author.new(data['author'])
188 @tree = Tree.new(@base, data['tree'])
189 @parents = data['parent'].map{ |sha| Commit.new(@base, sha) }
190 @message = data['message'].chomp
196 class Tag < AbstractObject
199 def initialize(base, sha, name)
213 # if we're calling this, we don't know what type it is yet
214 # so this is our little factory method
215 def new(base, objectish, is_tag = false)
217 sha = base.lib.tag_sha(objectish)
219 raise Git::GitTagNameDoesNotExist.new(objectish)
221 return Tag.new(base, sha, objectish)
223 sha = base.lib.revparse(objectish)
224 type = base.lib.object_type(sha)
230 when /commit/: Commit
233 klass::new(base, sha)