Class: RightGit::Git::Commit

Inherits:
Object
  • Object
show all
Defined in:
lib/right_git/git/commit.rb

Overview

A commit within a Git repository.

Defined Under Namespace

Classes: CommitError

Constant Summary collapse

COMMIT_INFO =
/^([0-9A-Fa-f]+) ([0-9]+) (.*)$/
COMMIT_SHA1_REGEX =
/^[0-9a-fA-F]{40}$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, line) ⇒ Commit

Returns a new instance of Commit.

Parameters:

  • repo (Repository)

    hosting commit

  • line (String)

    of git output describing commit



40
41
42
43
44
45
46
# File 'lib/right_git/git/commit.rb', line 40

def initialize(repo, line)
  @repo = repo
  unless match = COMMIT_INFO.match(line)
    raise CommitError, "Unrecognized commit summary: #{line.inspect}"
  end
  @info = [ match[1], Integer(match[2]), match[3] ]
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



34
35
36
# File 'lib/right_git/git/commit.rb', line 34

def repo
  @repo
end

Class Method Details

.sha?(revision) ⇒ TrueClass|FalseClass

Returns true if the given revision is a (fully qualified, not abbreviated) commit SHA.

Returns:

  • (TrueClass|FalseClass)

    true if the given revision is a (fully qualified, not abbreviated) commit SHA



71
72
73
# File 'lib/right_git/git/commit.rb', line 71

def self.sha?(revision)
  !!COMMIT_SHA1_REGEX.match(revision)
end

Instance Method Details

#authorString

Returns author of commit.

Returns:

  • (String)

    author of commit



66
67
68
# File 'lib/right_git/git/commit.rb', line 66

def author
  @info[2]
end

#hashString

Returns hash of commit (may be abbreviated).

Returns:

  • (String)

    hash of commit (may be abbreviated)



55
56
57
58
# File 'lib/right_git/git/commit.rb', line 55

def hash
  # This overrides String#hash on purpose
  @info[0]
end

#timestampTime

Returns time of commit.

Returns:

  • (Time)

    time of commit



61
62
63
# File 'lib/right_git/git/commit.rb', line 61

def timestamp
  ::Time.at(@info[1])
end

#to_sString Also known as: inspect

Returns stringized.

Returns:

  • (String)

    stringized



49
50
51
# File 'lib/right_git/git/commit.rb', line 49

def to_s
  "#{self.class.name}: #{@info.inspect}"
end