Class: RightGit::Git::Commit
- Inherits:
-
Object
- Object
- RightGit::Git::Commit
- Includes:
- BelongsToRepository
- Defined in:
- lib/right_git/git/commit.rb
Overview
A commit within a Git repository.
Defined Under Namespace
Classes: CommitError
Constant Summary collapse
- LOG_FORMAT_LONG =
"%H %at %aE %s"
- LOG_FORMAT =
"%h %at %aE %s"
- COMMIT_INFO =
/^([0-9A-Fa-f]+) ([0-9]+) (\S+) (.*)$/
- COMMIT_SHA1_REGEX =
/^[0-9a-fA-F]{40}$/
Instance Attribute Summary
Attributes included from BelongsToRepository
Class Method Summary collapse
-
.sha?(revision) ⇒ TrueClass|FalseClass
True if the given revision is a (fully qualified, not abbreviated) commit SHA.
Instance Method Summary collapse
-
#author ⇒ String
Author of commit.
-
#hash ⇒ String
The commit hash.
-
#initialize(repo, line) ⇒ Commit
constructor
A new instance of Commit.
-
#inspect ⇒ Object
Provide a programmer-friendly representation of this branch.
- #subject ⇒ String (also: #comment)
-
#timestamp ⇒ Time
Time of commit.
-
#to_s ⇒ Object
Provide a String representation of this commit (specifically, its commit hash).
Methods included from BelongsToRepository
Constructor Details
#initialize(repo, line) ⇒ Commit
Returns a new instance of 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], match[4] ] end |
Class Method Details
.sha?(revision) ⇒ TrueClass|FalseClass
Returns true if the given revision is a (fully qualified, not abbreviated) commit SHA.
83 84 85 |
# File 'lib/right_git/git/commit.rb', line 83 def self.sha?(revision) !!COMMIT_SHA1_REGEX.match(revision) end |
Instance Method Details
#author ⇒ String
Returns author of commit.
71 72 73 |
# File 'lib/right_git/git/commit.rb', line 71 def @info[2] end |
#hash ⇒ String
The commit hash. This overrides String#hash on purpose
61 62 63 |
# File 'lib/right_git/git/commit.rb', line 61 def hash @info[0] end |
#inspect ⇒ Object
Provide a programmer-friendly representation of this branch.
54 55 56 |
# File 'lib/right_git/git/commit.rb', line 54 def inspect '#<%s:%s>' % [self.class.name, hash] end |
#subject ⇒ String Also known as: comment
76 77 78 |
# File 'lib/right_git/git/commit.rb', line 76 def subject @info[3] end |
#timestamp ⇒ Time
Returns time of commit.
66 67 68 |
# File 'lib/right_git/git/commit.rb', line 66 def ::Time.at(@info[1]) end |
#to_s ⇒ Object
Provide a String representation of this commit (specifically, its commit hash).
49 50 51 |
# File 'lib/right_git/git/commit.rb', line 49 def to_s hash end |