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

Creates a commit object wrapper

Parameters:

  • base (Git::Repository) —

    the repository used to query object data

  • sha (String) —

    the commit SHA or object expression

  • init (Hash, nil) (defaults to: nil) —

    parsed commit data used to initialize eagerly



391
392
393
394
395
396
397
398
399
400
401
# File 'lib/git/object.rb', line 391

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::AuthorInfo

Returns the commit author identity

Returns:



448
449
450
451
# File 'lib/git/object.rb', line 448

def author
  check_commit
  @author
end

#author_date ⇒ Time

Returns the author date

Returns:

  • (Time) —

    the author timestamp



457
458
459
# File 'lib/git/object.rb', line 457

def author_date
  author.date
end

#commit? ⇒ Boolean

Returns whether this object is a commit

Returns:

  • (Boolean) —

    true



506
507
508
# File 'lib/git/object.rb', line 506

def commit?
  true
end

#committer ⇒ Git::AuthorInfo

Returns the commit committer identity

Returns:



465
466
467
468
# File 'lib/git/object.rb', line 465

def committer
  check_commit
  @committer
end

#committer_date ⇒ Time Also known as: date

Returns the committer date

Returns:

  • (Time) —

    the committer timestamp



474
475
476
# File 'lib/git/object.rb', line 474

def committer_date
  committer.date
end

#diff_parent ⇒ Git::Diff

Returns the diff between this commit and its first parent

Returns:

  • (Git::Diff) —

    the diff from the first parent to this commit



483
484
485
# File 'lib/git/object.rb', line 483

def diff_parent
  diff(parent)
end

#from_data(data)

This method returns an undefined value.

Loads parsed commit data into this commit object

Parameters:

  • data (Hash) —

    parsed commit data from git cat-file commit



493
494
495
496
497
498
499
500
# File 'lib/git/object.rb', line 493

def from_data(data)
  @sha ||= data['sha']
  @committer = Git::AuthorInfo.parse(data['committer'])
  @author = Git::AuthorInfo.parse(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 ⇒ Git::Object::Tree

Returns the tree for this commit

Returns:



424
425
426
427
# File 'lib/git/object.rb', line 424

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

#message ⇒ String

Returns the commit message

Returns:

  • (String) —

    the commit message without the trailing newline



407
408
409
410
# File 'lib/git/object.rb', line 407

def message
  check_commit
  @message
end

#name ⇒ String

Returns the symbolic name for this commit

Returns:

  • (String) —

    the name produced by git name-rev



416
417
418
# File 'lib/git/object.rb', line 416

def name
  object_repository.name_rev(sha)
end

#parent ⇒ Git::Object::Commit?

Returns the first parent commit

Returns:



434
435
436
# File 'lib/git/object.rb', line 434

def parent
  parents.first
end

#parents

array of all parent commits



439
440
441
442
# File 'lib/git/object.rb', line 439

def parents
  check_commit
  @parents
end