Class: Git::Object::Commit

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

Overview

A Git commit object

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.



212
213
214
215
216
217
218
219
220
221
222
# File 'lib/git/object.rb', line 212

def initialize(base, sha, init = nil)
  super(base, sha)
  @tree = nil
  @parents = nil
  @author = nil
  @committer = nil
  @message = nil
  return unless init

  from_data(init)
end

Instance Method Details

#author

git author



249
250
251
252
# File 'lib/git/object.rb', line 249

def author
  check_commit
  @author
end

#author_date



254
255
256
# File 'lib/git/object.rb', line 254

def author_date
  author.date
end

#commit?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/git/object.rb', line 290

def commit?
  true
end

#committer

git author



259
260
261
262
# File 'lib/git/object.rb', line 259

def committer
  check_commit
  @committer
end

#committer_date Also known as: date



264
265
266
# File 'lib/git/object.rb', line 264

def committer_date
  committer.date
end

#diff_parent



269
270
271
# File 'lib/git/object.rb', line 269

def diff_parent
  diff(parent)
end

#from_data(data)



281
282
283
284
285
286
287
288
# File 'lib/git/object.rb', line 281

def from_data(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

#gtree



233
234
235
236
# File 'lib/git/object.rb', line 233

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

#message



224
225
226
227
# File 'lib/git/object.rb', line 224

def message
  check_commit
  @message
end

#name



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

def name
  object_repository.name_rev(sha)
end

#parent



238
239
240
# File 'lib/git/object.rb', line 238

def parent
  parents.first
end

#parents

array of all parent commits



243
244
245
246
# File 'lib/git/object.rb', line 243

def parents
  check_commit
  @parents
end

#set_commit(data)

rubocop:disable Naming/AccessorMethodName



273
274
275
276
277
278
279
# File 'lib/git/object.rb', line 273

def set_commit(data) # rubocop:disable Naming/AccessorMethodName
  Git::Deprecation.warn(
    'Git::Object::Commit#set_commit is deprecated and will be removed in a future version. ' \
    'Use #from_data instead.'
  )
  from_data(data)
end