class
Agate::Commit
- Agate::Commit
- Reference
- Object
Overview
Represents a git commit object.
Defined in:
agate/commit.cragate/email.cr
agate/message.cr
Constructors
-
.lookup(repo : Repository, oid : OID) : Commit
Looks up a commit by OID.
Class Method Summary
-
.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.
-
.create_with_signature(repo : Repository, commit_content : String, signature : String, signature_field : String | Nil = nil) : OID
Creates a commit with a GPG signature.
-
.extract_signature(repo : Repository, oid : OID, field : String | Nil = nil) : Tuple(String, String) | Nil
Extracts the GPG signature from a commit.
-
.lookup?(repo : Repository, oid : OID) : Commit | Nil
Looks up a commit by OID, returning nil if not found.
Instance Method Summary
-
#==(other : Commit) : Bool
Compares two commits by OID.
-
#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.
-
#author : Signature
Returns the author signature.
-
#body : String | Nil
Returns the commit body (everything after the first blank line).
-
#committer : Signature
Returns the committer signature.
-
#diff(repo : Repository, parent_index : Int32 = 0) : Diff
Diffs this commit against a parent (defaults to first parent).
-
#diff_workdir(repo : Repository) : Diff
Diffs this commit's tree against the working directory.
-
#epoch_time : Int64
Returns the commit time as seconds since epoch.
-
#header : String
Returns the raw header of the commit.
-
#header_field(name : String) : String | Nil
Returns the value of a specific header field.
-
#message : String
Returns the full commit message.
-
#oid : OID
Returns the OID of this commit.
-
#parent_count : UInt32
Returns the number of parents.
-
#parent_ids : Array(OID)
Returns the OIDs of all parent commits.
-
#parents : Array(Commit)
Returns the parent commits.
-
#summary : String
Returns the commit summary (first line of message).
-
#time : Time
Returns the commit time as a Crystal Time.
-
#to_mbox : String
Formats the commit as an email/mbox message.
-
#trailers : Array(Tuple(String, String))
Returns the commit message trailers as an array of {key, value} pairs.
-
#tree : Tree
Returns the commit's tree object.
-
#tree_id : OID
Returns the OID of the commit's tree.
Constructor Detail
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="...")
Class Method Detail
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.
Creates a commit with a GPG signature.
Extracts the GPG signature from a commit. Returns {signature, signed_data} or nil if not signed.
Looks up a commit by OID, returning nil if not found.
Instance Method Detail
Amends this commit with new values. Pass nil for any field to keep the original value.
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.
Diffs this commit's tree against the working directory.
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..."
Returns the commit message trailers as an array of {key, value} pairs.
commit.trailers # => [{"Signed-off-by", "A User <a@b.com>"}]