reorder

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInterruptReorder = errors.Sentinel("interrupt reorder")

ErrInterruptReorder is an error that is returned by Cmd implementations when the reorder operation should be suspended (and later resumed with --continue, --skip, or --reorder).

Functions

func WriteContinuation added in v0.0.17

func WriteContinuation(repo *git.Repo, continuation *Continuation) error

WriteContinuation writes a continuation to the state file. If a nil continuation is passed, the state file is deleted.

Types

type Cmd

type Cmd interface {
	// Execute executes the command.
	Execute(ctx *Context) error
	// String returns a string representation of the command.
	// The string representation must be parseable such that
	// ParseCmd(cmd.String()) == cmd.
	String() string
}

func CreatePlan added in v0.0.17

func CreatePlan(repo *git.Repo, tx meta.ReadTx, rootBranch string) ([]Cmd, error)

CreatePlan creates a reorder plan for the stack rooted at rootBranch.

func EditPlan added in v0.0.17

func EditPlan(repo *git.Repo, plan []Cmd) ([]Cmd, error)

EditPlan opens the user's editor and allows them to edit the plan.

func ParseCmd

func ParseCmd(line string) (Cmd, error)

ParseCmd parses a reorder command from a string. Comments must be stripped from the input before calling this function.

type Context

type Context struct {
	// Repo is the repository the reorder operation is being performed on.
	Repo *git.Repo
	// DB is the av database of the repository.
	DB meta.DB
	// State is the current state of the reorder operation.
	State *State
	// Output is the output stream to write interactive messages to.
	// Commands should write to this stream instead of stdout/stderr.
	Output io.Writer
}

Context is the context of a reorder operation. Commands can use the context to access the current state of the reorder.

func (*Context) Print

func (c *Context) Print(a ...any)

type Continuation

type Continuation struct {
	State *State
}

func ReadContinuation added in v0.0.17

func ReadContinuation(repo *git.Repo) (*Continuation, error)

ReadContinuation reads a continuation from the state file. Returns the raw error returned by os.Open if the file couldn't be opened. Use os.IsNotExist to check if the continuation doesn't exist.

func Reorder

func Reorder(ctx Context) (*Continuation, error)

Reorder executes a reorder. If the reorder couldn't be completed (due to a conflict), a continuation is returned. If the reorder was completed successfully, a nil continuation and nil error is returned.

type DeleteBranchCmd added in v0.0.17

type DeleteBranchCmd struct {
	Name string
	// If true, delete the branch from Git as well as from the internal database.
	// If false, only delete the branch metadata from the internal database.
	DeleteGitRef bool
}

DeleteBranchCmd is a command that deletes a branch. This is for internal use only to clean up branches that were removed from a re-order operation.

func (DeleteBranchCmd) Execute added in v0.0.17

func (d DeleteBranchCmd) Execute(ctx *Context) error

func (DeleteBranchCmd) String added in v0.0.17

func (d DeleteBranchCmd) String() string

type ErrInvalidCmd

type ErrInvalidCmd struct {
	Cmd    string
	Reason string
}

func (ErrInvalidCmd) Error

func (e ErrInvalidCmd) Error() string

type PickCmd

type PickCmd struct {
	Commit  string
	Comment string
}

PickCmd is a command that picks a commit from the history and applies it on top of the current HEAD.

func (PickCmd) Execute

func (p PickCmd) Execute(ctx *Context) error

func (PickCmd) String

func (p PickCmd) String() string

type PlanDiff added in v0.0.17

type PlanDiff struct {
	RemovedBranches []string
	AddedBranches   []string
}

func Diff added in v0.0.17

func Diff(old []Cmd, new []Cmd) PlanDiff

type StackBranchCmd

type StackBranchCmd struct {
	// The name of the branch to create.
	Name string
	// The name of the parent branch. If not specified, the previous branch in
	// the reorder stack is used (or an error is raised if there is no previous
	// branch).
	// Mutually exclusive with --trunk.
	Parent string
	// The name of the trunk branch.
	// Mutually exclusive with --parent.
	// The branch can be rooted at a given commit by appending "@<commit>" to the
	// branch name.
	Trunk string
	// An optional comment to include in the reorder plan for this command.
	Comment string
}

StackBranchCmd is a command to create a new branch in a stack.

stack-branch <branch-name> [--parent <parent-branch-name>] [--trunk <trunk-branch-name>]

func (StackBranchCmd) Execute

func (b StackBranchCmd) Execute(ctx *Context) error

func (StackBranchCmd) String

func (b StackBranchCmd) String() string

type State

type State struct {
	// The current HEAD of the reorder operation.
	Head string `json:"head"`
	// The name of the current branch in the reorder operation.
	Branch string `json:"branch"`
	// The sequence of commands to be executed.
	// NOTE: we handle marshalling/unmarshalling in the MarshalJSON/UnmarshalJSON methods.
	Commands []Cmd `json:"-"`
}

State is the state of a reorder operation. It is meant to be serializable to allow the user to continue/abort a reorder operation if there is a conflict.

func (*State) MarshalJSON

func (s *State) MarshalJSON() ([]byte, error)

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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