Help us shape the future of Go! Take the 2026 Go Developer Survey

jj

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package jj shells out to the jj binary for the diff, status, and revision data the UI needs, and carries the one write path that moves selected changes into another revision.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeType

type ChangeType int

ChangeType is what jj status says happened to a file. String returns the one-letter status jj prints.

const (
	ChangeTypeModified ChangeType = iota
	ChangeTypeAdded
	ChangeTypeDeleted
	ChangeTypeRenamed
)

Change kinds a status line can report. ChangeTypeModified is the zero value and the fallback for a status letter that is not recognized.

func (ChangeType) String

func (ct ChangeType) String() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client runs jj in one repository. Every call shells out and blocks, so callers in the UI wrap them in a tea.Cmd. No call is cancellable, so each one runs under a background context.

func NewClient

func NewClient(baseDir string) *Client

NewClient runs jj with baseDir as the working directory, so baseDir decides which repository every call acts on.

func (*Client) ApplySplit

func (c *Client) ApplySplit(plans []SplitPlan, source string) error

ApplySplit runs the plans in order, creating a commit first for each plan that needs one. A failure part way through restores the operation recorded before the first plan, so the repository goes back to where it started rather than keeping the plans that already succeeded.

This is the one path that rebases source, because a plan targeting a new commit inserts that commit beneath source. Only the parent pointer moves; source keeps every byte it had, so an unselected change cannot be lost here.

func (*Client) CheckInstalled

func (*Client) CheckInstalled() error

CheckInstalled reports whether a jj binary is on PATH. It runs outside the repository, so it says nothing about baseDir being a jj repo.

func (*Client) Diff

func (c *Client) Diff(revision string) (string, error)

Diff returns the git-format diff for a revset, uncolored. The revset is resolved by jj at call time, so a moving revset such as @ follows the working copy.

func (*Client) GetRevisions

func (c *Client) GetRevisions(limit int) ([]RevisionEntry, error)

GetRevisions lists recent revisions newest first for the destination picker, defaulting to 20 when limit is not positive.

func (*Client) MoveChanges

func (c *Client) MoveChanges(patch, _, destination string) (err error)

MoveChanges applies a patch onto destination and squashes it there. Nothing the patch does not carry is touched: the caller's working copy is never read, written, or moved by the sequence, because every write happens in a throwaway workspace. The temp file holding the patch is removed even on failure, and a failure to remove it is joined onto the returned error.

func (*Client) ShowRevision

func (c *Client) ShowRevision(revision string) (*RevisionInfo, error)

ShowRevision returns one revision's metadata. Fields jj did not print are left empty rather than reported, so the result is never nil on success.

func (*Client) Status

func (c *Client) Status() ([]FileStatus, error)

Status lists the working copy's changed files. Lines jj prints that are not file entries are dropped, so an unparsable output yields an empty slice rather than an error.

func (*Client) Undo

func (c *Client) Undo() error

Undo reverts the last jj operation in the repository, whether or not this client caused it.

type FileStatus

type FileStatus struct {
	Path       string
	ChangeType ChangeType
}

FileStatus is one entry from jj status.

type RevisionEntry

type RevisionEntry struct {
	ChangeID    string
	Description string
}

RevisionEntry is one row of the destination picker. ChangeID is jj's shortest unique prefix, so it is only valid against the repository it came from.

type RevisionInfo

type RevisionInfo struct {
	ChangeID    string
	Description string
	Author      string
	Date        string
}

RevisionInfo is one revision's metadata as jj show prints it. Any field jj omitted is empty.

type SplitDestination

type SplitDestination struct {
	ChangeID    string
	Description string
	Type        SplitDestinationType
}

SplitDestination is where one split plan's patch lands. ChangeID is empty for SplitDestNewCommit, where Description becomes the message of the commit that gets created.

type SplitDestinationType

type SplitDestinationType int

SplitDestinationType separates a split target that already exists from one that will be created.

const (
	SplitDestExistingRevision SplitDestinationType = iota
	SplitDestNewCommit
)

Targets a split plan can send its patch to. SplitDestExistingRevision is the zero value, so a SplitDestination that was never filled in reads as targeting an existing revision.

type SplitPlan

type SplitPlan struct {
	Patch       string
	Destination SplitDestination
	Tag         rune
}

SplitPlan is one tag's patch and the destination it goes to. Tag is carried through for error messages and has no meaning to jj.

Jump to

Keyboard shortcuts

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