Class: Git::Object::Commit

Inherits:
AbstractObject show all
Defined in:
lib/git/object.rb

Instance Attribute Summary

Attributes inherited from AbstractObject

#mode, #objectish, #size, #type

Instance Method Summary collapse

Methods inherited from AbstractObject

#archive, #blob?, #contents, #contents_array, #diff, #grep, #log, #sha, #tag?, #to_s, #tree?

Constructor Details

#initialize(base, sha, init = nil) ⇒ Commit

Returns a new instance of Commit.



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/git/object.rb', line 160

def initialize(base, sha, init = nil)
  super(base, sha)
  @tree = nil
  @parents = nil
  @author = nil
  @committer = nil
  @message = nil
  if init
    set_commit(init)
  end
end

Instance Method Details

#author

git author



197
198
199
200
# File 'lib/git/object.rb', line 197

def author
  check_commit
  @author
end

#author_date



202
203
204
# File 'lib/git/object.rb', line 202

def author_date
  author.date
end

#commit?Boolean

Returns:

  • (Boolean)


230
231
232
# File 'lib/git/object.rb', line 230

def commit?
  true
end

#committer

git author



207
208
209
210
# File 'lib/git/object.rb', line 207

def committer
  check_commit
  @committer
end

#committer_date Also known as: date



212
213
214
# File 'lib/git/object.rb', line 212

def committer_date
  committer.date
end

#diff_parent



217
218
219
# File 'lib/git/object.rb', line 217

def diff_parent
  diff(parent)
end

#gtree



181
182
183
184
# File 'lib/git/object.rb', line 181

def gtree
  check_commit
  Tree.new(@base, @tree)
end

#message



172
173
174
175
# File 'lib/git/object.rb', line 172

def message
  check_commit
  @message
end

#name



177
178
179
# File 'lib/git/object.rb', line 177

def name
  @base.lib.name_rev(sha)
end

#parent



186
187
188
# File 'lib/git/object.rb', line 186

def parent
  parents.first
end

#parents

array of all parent commits



191
192
193
194
# File 'lib/git/object.rb', line 191

def parents
  check_commit
  @parents
end

#set_commit(data)



221
222
223
224
225
226
227
228
# File 'lib/git/object.rb', line 221

def set_commit(data)
  @sha ||= data['sha']
  @committer = Git::Author.new(data['committer'])
  @author = Git::Author.new(data['author'])
  @tree = Git::Object::Tree.new(@base, data['tree'])
  @parents = data['parent'].map{ |sha| Git::Object::Commit.new(@base, sha) }
  @message = data['message'].chomp
end