trailers

package
v0.13.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 5 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package trailers provides parsing and formatting for Entire commit message trailers. Trailers are key-value metadata appended to git commit messages following the git trailer convention (key: value format after a blank line).

Index

Constants

View Source
const (
	// MetadataTrailerKey points to the metadata directory within a commit tree.
	MetadataTrailerKey = "Entire-Metadata"

	// StrategyTrailerKey indicates which strategy created the commit.
	StrategyTrailerKey = "Entire-Strategy"

	// SessionTrailerKey identifies which session created a commit.
	SessionTrailerKey = "Entire-Session"

	// CheckpointTrailerKey links commits to their checkpoint metadata on entire/checkpoints/v1.
	// Format: a checkpoint ID — either a legacy 12-hex ID (e.g. "a3b2c4d5e6f7")
	// or a 26-char ULID (see checkpoint/id.CheckpointPattern).
	// This trailer survives git amend and rebase operations.
	CheckpointTrailerKey = "Entire-Checkpoint"

	// AgentTrailerKey identifies the agent that created a checkpoint.
	// Format: human-readable agent name e.g. "Claude Code", "Cursor"
	AgentTrailerKey = "Entire-Agent"

	// OPFAppliedTrailerKey marks an entire/checkpoints/v1 commit whose blobs
	// have been redacted by the OpenAI Privacy Filter (the opt-in 9th,
	// network-backed layer, applied on top of the 8 regex layers).
	// Format: literal "true"; the trailer is omitted entirely when OPF was
	// not applied. The pre-push rewrite path treats commits lacking this
	// trailer as candidates to OPF-redact before they reach the remote.
	OPFAppliedTrailerKey = "Entire-OPF-Applied"

	// OPFAppliedTrailerValue is the only value that means "OPF ran." Any
	// other value (or trailer absence) is treated as "not applied" so a
	// future "false" / "skipped" value never accidentally enables OPF.
	OPFAppliedTrailerValue = "true"
)

Trailer key constants used in commit messages.

View Source
const DefaultCommentPrefix = "#"

DefaultCommentPrefix is git's comment prefix when core.commentChar is unset.

Variables

This section is empty.

Functions

func AppendCheckpointTrailer added in v0.5.3

func AppendCheckpointTrailer(message, checkpointID string) string

AppendCheckpointTrailer appends Entire-Checkpoint in trailer-aware format (see appendTrailerLine).

func AppendOPFAppliedTrailer added in v0.7.8

func AppendOPFAppliedTrailer(message string) string

AppendOPFAppliedTrailer appends `Entire-OPF-Applied: true` in trailer-aware format. Idempotent: if the message already carries the trailer with value "true", the original message is returned unchanged so re-parenting an already-applied commit doesn't duplicate the trailer.

func AutoCommentPrefix added in v0.13.0

func AutoCommentPrefix(message string, mayHaveBlock bool, rule AutoRule) string

AutoCommentPrefix returns the prefix git chose for core.commentChar=auto: the first of autoCommentCandidates that starts no line of the message, by rule, picked before git adds its comment block. When git may have written that block (mayHaveBlock: commit.status is on), its lines start with the choice, so it is read back from them: the scissors line if there is one, else the run of lines ending the message, below at least one other line, that start with the prefix git would pick for the lines above them. No blank line is needed above that run: git writes its block right below a message that lacks a final newline, and no line above the block can start with git's choice. A message without one was not opened in the editor.

func CutAtScissors added in v0.13.0

func CutAtScissors(message, commentPrefix string) string

CutAtScissors returns message without git's scissors line for commentPrefix and everything below it, which git discards from a `commit -v` message. An empty commentPrefix returns message unchanged.

func EditorCommentBlockStart added in v0.13.0

func EditorCommentBlockStart(lines []string, commentPrefix string) int

EditorCommentBlockStart returns the index of the line where the comment block git appends to a message it opens in the editor starts. Git writes a blank line and then only comment lines, ending the message or, with `commit -v`, the part above the scissors line; under commit.cleanup=scissors the scissors line can start the block itself. So the block is the run of commentPrefix lines that ends the message, or ends it above the scissors line, with a blank line right above it, else the scissors line. It returns -1 when there is neither, or commentPrefix is empty: comment lines joined to the paragraph above them, or making up the whole message, are the user's.

func FormatCheckpoint

func FormatCheckpoint(message string, cpID checkpointID.CheckpointID) string

FormatCheckpoint creates a commit message with a checkpoint trailer. This links user commits to their checkpoint metadata on entire/checkpoints/v1 branch.

func HasOPFApplied added in v0.7.8

func HasOPFApplied(commitMessage string) bool

HasOPFApplied reports whether the commit message carries an `Entire-OPF-Applied: true` trailer. Any other value (or absence) is treated as "OPF not applied" so the pre-push rewrite considers the commit a candidate for OPF redaction. Pinning the value to literal "true" — rather than just trailer presence — prevents a future "Entire-OPF-Applied: false" or "skipped" from accidentally meaning "yes, applied."

The trailer marks commits Entire rewrites, not user commits, so a message that is only a trailer block counts too.

func IsTrailerLine added in v0.5.3

func IsTrailerLine(line string) bool

IsTrailerLine reports whether a line matches git trailer format.

func ParseAllCheckpoints added in v0.5.0

func ParseAllCheckpoints(commitMessage string) []checkpointID.CheckpointID

ParseAllCheckpoints extracts all checkpoint IDs from a commit message. Returns a slice of CheckpointIDs (may be empty if none found). Duplicate IDs are deduplicated while preserving order. This is useful for squash merge commits that contain multiple Entire-Checkpoint trailers. Like ParseCheckpoint, it discovers IDs; it does not tell which one the commit links.

func ParseAllCheckpointsFromFinalTrailerBlock added in v0.13.0

func ParseAllCheckpointsFromFinalTrailerBlock(commitMessage, commentPrefix string) []checkpointID.CheckpointID

ParseAllCheckpointsFromFinalTrailerBlock extracts checkpoint IDs from the final trailer block, deduplicating them while preserving order. Lines starting with commentPrefix are skipped, as git's trailer grammar does; an empty commentPrefix reads every line as written.

func ParseCheckpoint

func ParseCheckpoint(commitMessage string) (checkpointID.CheckpointID, bool)

ParseCheckpoint discovers the first checkpoint ID anywhere in a commit message, squash history included. Code deciding which checkpoint to create, join or write into reads only the final trailer block (strategy.LinkedCheckpoints). Returns the CheckpointID and true if found, empty ID and false otherwise.

func ParseMetadata

func ParseMetadata(commitMessage string) (string, bool)

ParseMetadata extracts metadata dir from commit message. Returns the metadata directory and true if found, empty string and false otherwise.

func ParseSession

func ParseSession(commitMessage string) (string, bool)

ParseSession extracts the session ID from a commit message. Returns the session ID and true if found, empty string and false otherwise. Note: If multiple Entire-Session trailers exist, this returns only the first one.

func RemoveCheckpointTrailers added in v0.11.5

func RemoveCheckpointTrailers(message string, drop func(checkpointID.CheckpointID) bool) (string, []checkpointID.CheckpointID)

RemoveCheckpointTrailers removes every whole Entire-Checkpoint trailer line whose ID drop selects, anywhere between the subject paragraph and a scissors line, and returns the new message with the IDs removed (nil when the message is unchanged). It does not try to reproduce git's trailer-block rules (mixed blocks, a "(cherry picked from ...)" note, custom comment characters): a line that is exactly a checkpoint trailer is one in every form git accepts, and leaving one behind would let an amend keep a deleted checkpoint alive. Indentation is ignored, since a squash message indents the squashed commits' messages. Prose that merely mentions an ID is not a whole trailer line and stays. Blank lines a removal leaves doubled are collapsed, and trailing blank lines are trimmed unless a scissors line follows; nothing at or below the scissors line is touched.

func ScissorsLineIndex added in v0.13.0

func ScissorsLineIndex(lines []string, commentPrefix string) int

ScissorsLineIndex returns the index of git's scissors line for commentPrefix in lines, or -1.

func StripEditorComments added in v0.13.0

func StripEditorComments(message, commentPrefix string) string

StripEditorComments returns an editor-written commit message without the lines git's default cleanup drops before the commit is recorded: everything from the scissors line down, and every line starting with commentPrefix. An empty commentPrefix, for a -m or -F message whose lines git keeps as written, returns message unchanged.

Types

type AutoRule added in v0.13.0

type AutoRule int

AutoRule is how a git version picks the character for core.commentChar=auto.

const (
	// AutoSkipsTrailingComments is git's rule since 2.51: the empty and "#"
	// lines that end the message, and an old "Conflicts:" block, do not
	// count, as when git places a sign-off (ignored_log_message_bytes).
	AutoSkipsTrailingComments AutoRule = iota
	// AutoCountsEveryLine is git's rule before 2.51.
	AutoCountsEveryLine
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL