class Agate::Commit

Overview

Represents a git commit object.

Defined in:

agate/commit.cr
agate/email.cr
agate/message.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.lookup(repo : Repository, oid : OID) : Commit #

Looks up a commit by OID. Raises on failure.

oid = Object.rev_parse_oid(repo, "HEAD")
commit = Commit.lookup(repo, oid)
commit.message # => "Initial commit\n"
commit.author  # => Signature(@name="...", @email="...")

[View source]

Class Method Detail

def self.create(repo : Repository, message : String, tree : Tree, author : Signature, committer : Signature, parents : Array(Commit) = [] of Commit, update_ref : String | Nil = "HEAD") : OID #

Creates a new commit in the repository.

  • repo: the repository
  • message: the commit message
  • tree: the tree to commit (as a Tree object)
  • author: the author signature
  • committer: the committer signature
  • parents: parent commits (empty for initial commit)
  • update_ref: reference to update (e.g., "HEAD"), or nil

Returns the OID of the new commit.


[View source]
def self.create_with_signature(repo : Repository, commit_content : String, signature : String, signature_field : String | Nil = nil) : OID #

Creates a commit with a GPG signature.


[View source]
def self.extract_signature(repo : Repository, oid : OID, field : String | Nil = nil) : Tuple(String, String) | Nil #

Extracts the GPG signature from a commit. Returns {signature, signed_data} or nil if not signed.


[View source]
def self.lookup?(repo : Repository, oid : OID) : Commit | Nil #

Looks up a commit by OID, returning nil if not found.


[View source]

Instance Method Detail

def ==(other : Commit) : Bool #

Compares two commits by OID.


[View source]
def amend(message : String | Nil = nil, author : Signature | Nil = nil, committer : Signature | Nil = nil, tree : Tree | Nil = nil, update_ref : String | Nil = "HEAD") : OID #

Amends this commit with new values. Pass nil for any field to keep the original value.


[View source]
def author : Signature #

Returns the author signature.


[View source]
def body : String | Nil #

Returns the commit body (everything after the first blank line).


[View source]
def committer : Signature #

Returns the committer signature.


[View source]
def diff(repo : Repository, parent_index : Int32 = 0) : Diff #

Diffs this commit against a parent (defaults to first parent). For an initial commit (no parents), diffs against an empty tree. Requires the repository since Commit doesn't store a back-reference.


[View source]
def diff_workdir(repo : Repository) : Diff #

Diffs this commit's tree against the working directory.


[View source]
def epoch_time : Int64 #

Returns the commit time as seconds since epoch.


[View source]
def header : String #

Returns the raw header of the commit.


[View source]
def header_field(name : String) : String | Nil #

Returns the value of a specific header field.


[View source]
def message : String #

Returns the full commit message.


[View source]
def oid : OID #

Returns the OID of this commit.


[View source]
def parent_count : UInt32 #

Returns the number of parents.


[View source]
def parent_ids : Array(OID) #

Returns the OIDs of all parent commits.


[View source]
def parents : Array(Commit) #

Returns the parent commits.


[View source]
def summary : String #

Returns the commit summary (first line of message).


[View source]
def time : Time #

Returns the commit time as a Crystal Time.


[View source]
def to_mbox : String #

Formats the commit as an email/mbox message.

commit = Commit.lookup(repo, oid)
commit.to_mbox # => "From <oid> Mon Sep 17 00:00:00 2001\n..."

[View source]
def trailers : Array(Tuple(String, String)) #

Returns the commit message trailers as an array of {key, value} pairs.

commit.trailers # => [{"Signed-off-by", "A User <a@b.com>"}]

[View source]
def tree : Tree #

Returns the commit's tree object.


[View source]
def tree_id : OID #

Returns the OID of the commit's tree.


[View source]