restack

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package restack implements business logic for high-level restack operations.

Index

Constants

View Source
const (
	// ScopeBranch selects just the branch specified in the request.
	ScopeBranch Scope = 1 << iota

	// ScopeUpstackExclusive selects the upstack of a branch,
	// excluding the branch itself.
	ScopeUpstackExclusive

	// ScopeUpstack selects the upstack of a branch,
	// including the branch itself.
	ScopeUpstack = ScopeBranch | ScopeUpstackExclusive

	// ScopeDownstack selects the downstack of a branch,
	// including the branch itself.
	ScopeDownstack = ScopeBranch | scopeDownstackExclusive

	// ScopeStack selects the full stack of a branch:
	// the upstack, downstack, and the branch itself.
	ScopeStack = ScopeUpstack | ScopeDownstack
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GitWorktree

type GitWorktree interface {
	CurrentBranch(ctx context.Context) (string, error)
	Checkout(ctx context.Context, branch string) error
	RootDir() string
}

GitWorktree is a subet of the git.Worktree interface.

type Handler

type Handler struct {
	Log      *silog.Logger // required
	Worktree GitWorktree   // required
	Store    Store         // required
	Service  Service       // required
}

Handler implements various restack operations.

func (*Handler) Restack

func (h *Handler) Restack(ctx context.Context, req *Request) (int, error)

Restack restacks one or more branches according to the request.

func (*Handler) RestackBranch

func (h *Handler) RestackBranch(ctx context.Context, branch string) error

RestackBranch restacks the given branch onto its base.

func (*Handler) RestackStack

func (h *Handler) RestackStack(ctx context.Context, branch string) error

RestackStack restacks the stack of the given branch. This includes all upstack and downtrack branches, as well as the branch itself.

func (*Handler) RestackUpstack

func (h *Handler) RestackUpstack(ctx context.Context, branch string, opts *UpstackOptions) error

RestackUpstack restacks the upstack of the given branch, including the branch itself, unless SkipStart is set.

type Request

type Request struct {
	// Branch is the starting point for the restack operation.
	// This branch will be checked out at the end of the operation.
	//
	// Scope is relative to this branch.
	Branch string // required

	// ContinueCommand specifies the git-spice command
	// to run from the Branch's context
	// to resume this operation if it is interrupted
	// due to a conflict.
	ContinueCommand []string // required

	// Scope specifies which branches are affected by the restack operation.
	//
	// Defaults to ScopeBranch.
	Scope Scope
}

Request is a request to restack one or more branches.

type Scope

type Scope int

Scope specifies which branches are affected by a restack operation.

type Service

type Service interface {
	BranchGraph(ctx context.Context, opts *spice.BranchGraphOptions) (*spice.BranchGraph, error)
	Restack(ctx context.Context, name string) (*spice.RestackResponse, error)
	RebaseRescue(ctx context.Context, req spice.RebaseRescueRequest) error
}

Service is a subset of the spice.Service interface.

type Store

type Store interface {
	Trunk() string
}

Store is a subset of the state.Store interface.

type UpstackOptions

type UpstackOptions struct {
	// SkipStart indicates that the starting branch should not be restacked.
	SkipStart bool `help:"Do not restack the starting branch"`
}

UpstackOptions holds options for restacking the upstack of a branch.

Jump to

Keyboard shortcuts

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