gitmail

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package gitmail applies patches received as email to a local git working tree. It is matcha's "git-mail" feature: a message produced by `git format-patch` / `git send-email` can be applied to a checkout without shelling out to git, using floatpane's parser and applier libraries.

  • github.com/floatpane/go-mailpatch parses the RFC 5322 message into commit metadata and a structured diff.
  • github.com/floatpane/go-patchapply writes the diff to a directory, confined to that directory and applied transactionally.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPatch

func FormatPatch(opts mailpatch.FormatOptions) ([]byte, error)

FormatPatch constructs a format-patch email from structured data using the go-mailpatch Format function. This is useful when you have the diff already and want to construct a proper email without running git.

func GeneratePatch

func GeneratePatch(repoDir, commitRange string) ([]byte, error)

GeneratePatch generates a format-patch email from a local git repository. It runs `git format-patch --stdout` for the given commit range and returns the raw email bytes.

func GeneratePatchSeries

func GeneratePatchSeries(repoDir, commitRange string) ([]byte, error)

GeneratePatchSeries generates a multi-patch mbox from a local git repository.

func IsPatch

func IsPatch(raw []byte) bool

IsPatch reports whether raw looks like an applicable patch email: it parses and carries a diff. Use it to decide whether to offer "apply" on a message.

func ParsePatch

func ParsePatch(raw []byte) (*mailpatch.Patch, error)

ParsePatch parses raw format-patch email bytes and returns the structured Patch.

Types

type Options

type Options struct {
	// Reverse unapplies the patch instead of applying it.
	Reverse bool
	// DryRun validates the patch against the tree but writes nothing.
	DryRun bool
}

Options controls how a patch is applied.

type SendOptions

type SendOptions struct {
	// To is the primary recipient address list, comma-separated (required).
	To string
	// Cc is the carbon-copy recipient list, comma-separated.
	Cc string
	// Subject overrides the patch subject. If empty, the commit subject is used.
	Subject string
	// Version is the series revision (1 default, 2 for v2, etc.).
	Version int
	// InReplyTo is the Message-ID this patch replies to (for threading).
	InReplyTo string
	// References is the full References header value (space-separated Message-IDs).
	References string
}

SendOptions describes how to generate and send a patch email from a local repo.

type Summary

type Summary struct {
	// Subject is the patch subject with its "[PATCH n/m]" prefix stripped.
	Subject string
	// Author is the commit author ("Name <email>").
	Author string
	// Series is the position within a series, when the subject carried it.
	Series mailpatch.SeriesInfo
	// CoverLetter is true when the message is a "0/n" cover letter (nothing to
	// apply); Files is then empty.
	CoverLetter bool
	// Files lists what was created, updated, removed, or renamed.
	Files []patchapply.FileResult
}

Summary describes the result of applying one patch message.

func Apply

func Apply(raw []byte, repoDir string, opts Options) (*Summary, error)

Apply parses a single format-patch email (raw RFC 5322 bytes) and applies it to the working tree rooted at repoDir. A cover letter (a "0/n" message with no diff) applies cleanly as a no-op.

func ApplySeries

func ApplySeries(raw []byte, repoDir string, opts Options) ([]*Summary, error)

ApplySeries applies every patch in an mbox to repoDir in series order. The cover letter, if present, is summarized but applies nothing.

It is not transactional across patches: if patch 3 of 5 conflicts, patches 1 and 2 are already written. Pass Options.DryRun first to check the whole series, or reverse the applied prefix yourself on failure.

Jump to

Keyboard shortcuts

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