rebase

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package rebase provides types and parsing for declarative rebase specifications. This enables AI agents to describe rebase operations without interactive prompts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateTodoFromEntries

func GenerateTodoFromEntries(entries []TodoEntry) string

GenerateTodoFromEntries generates a todo file from entries.

Types

type Action

type Action struct {
	// Action is the type of operation (pick, squash, drop, etc.).
	Action ActionType `json:"action"`

	// Commit is the commit hash (required for all actions except exec).
	Commit string `json:"commit,omitempty"`

	// Message is the commit message for reword/squash operations.
	// If empty during squash, git will prompt for message concatenation.
	Message string `json:"message,omitempty"`

	// Command is the shell command for exec actions.
	Command string `json:"command,omitempty"`
}

Action represents a single rebase operation.

func (*Action) Validate

func (a *Action) Validate() error

Validate checks that the action is valid.

type ActionType

type ActionType string

ActionType represents a rebase action (pick, squash, etc.).

const (
	ActionPick   ActionType = "pick"
	ActionReword ActionType = "reword"
	ActionEdit   ActionType = "edit"
	ActionSquash ActionType = "squash"
	ActionFixup  ActionType = "fixup"
	ActionDrop   ActionType = "drop"
	ActionExec   ActionType = "exec"
)

func (ActionType) ShortForm

func (a ActionType) ShortForm() string

ShortForm returns the single-letter abbreviation for the action.

func (ActionType) Valid

func (a ActionType) Valid() bool

Valid returns true if the action type is recognized.

type Spec

type Spec struct {
	// Actions is the ordered list of rebase operations.
	Actions []Action `json:"actions"`
}

Spec is a complete rebase specification.

func ParseCLISpec

func ParseCLISpec(args []string) (*Spec, error)

ParseCLISpec parses the CLI shorthand syntax.

Supported formats:

  • "abc123,def456" - pick all commits
  • "pick:abc123,squash:def456" - explicit actions
  • "reword:abc123:New message" - action with message
  • "exec:make test" - exec command

func ParseSpec

func ParseSpec(data []byte) (*Spec, error)

ParseSpec parses a Spec from JSON data.

func (*Spec) ToTodoFile

func (s *Spec) ToTodoFile() string

ToTodoFile generates a git rebase todo file from the spec. The output format matches what git expects.

func (*Spec) ToTodoFileWithMessages

func (s *Spec) ToTodoFileWithMessages() string

ToTodoFileWithMessages generates a todo file with message handling. For reword actions with messages, it uses fixup -C to set the message. This is a more advanced format for message control.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate checks that the spec is valid.

func (*Spec) ValidateAgainstCommits

func (s *Spec) ValidateAgainstCommits(original []TodoEntry) error

ValidateAgainstCommits checks that the spec actions reference valid commits from the original todo file.

type TodoEntry

type TodoEntry struct {
	// Action is the rebase action (pick, squash, etc.).
	Action ActionType

	// Commit is the commit hash.
	Commit string

	// Subject is the commit subject line.
	Subject string
}

TodoEntry represents a single entry in a git rebase todo file.

func ParseTodoFile

func ParseTodoFile(content string) []TodoEntry

ParseTodoFile parses a git rebase todo file into entries. Ignores comments (lines starting with #) and empty lines.

func ReorderToMatchSpec

func ReorderToMatchSpec(spec *Spec, original []TodoEntry) ([]TodoEntry, error)

ReorderToMatchSpec reorders the original todo entries to match the spec. This preserves full commit hashes and subjects from the original.

Jump to

Keyboard shortcuts

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