jujutsu

package
v1.10.10 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package jujutsu provides jj (Jujutsu) VCS operations for agent-deck. It mirrors the internal/git package pattern with package-level functions that execute jj CLI commands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbortMerge

func AbortMerge(repoDir string) error

AbortMerge undoes the last operation (equivalent to aborting a merge).

func BookmarkExists added in v1.9.51

func BookmarkExists(repoDir, name string) (bool, error)

BookmarkExists reports whether a jj bookmark (branch) named name exists in the repo. The name is passed with jj's "exact:" string-pattern prefix because a bare positional name is matched as a GLOB by default — so a name containing a glob metacharacter (or one that is a glob-prefix of a real bookmark) would otherwise report a false-positive collision. (jj 0.42.0 rejects the --name flag entirely; the pattern must be positional.)

func CreateWorkspaceAtRevision added in v1.9.51

func CreateWorkspaceAtRevision(repoDir, workspacePath, branchName, revision string) error

CreateWorkspaceAtRevision creates a new jj workspace at workspacePath whose working copy is anchored at revision (the parent session's committed point), then creates branchName as a bookmark on the new workspace's @. Existing bookmarks are refused because with-state forks must create a fresh destination, matching the git path's collision semantics.

This is the jj equivalent of git.CreateWorktreeAtStartPoint: it differs from the plain CreateWorktree only by pinning the start revision, which is what lets a subsequent MaterializeWipFromParent reproduce the parent's WIP as uncommitted changes rather than as an extra ancestor commit.

func GetMainWorktreePath

func GetMainWorktreePath(dir string) (string, error)

GetMainWorktreePath returns the path to the default workspace.

func GetRepoRoot

func GetRepoRoot(dir string) (string, error)

GetRepoRoot returns the root directory of the jj repository.

func GetWorktreeBaseRoot

func GetWorktreeBaseRoot(dir string) (string, error)

GetWorktreeBaseRoot returns the default workspace path (equivalent to main worktree in git).

func IsDefaultWorkspace

func IsDefaultWorkspace(dir string) (bool, error)

IsDefaultWorkspace returns true if the given directory is the default workspace.

func IsJJRepo

func IsJJRepo(dir string) bool

IsJJRepo checks if the given directory is inside a jj repository by running `jj root`. Returns false if jj is not installed or the directory is not a jj repo.

func IsWorktree

func IsWorktree(dir string) bool

IsWorktree checks if the directory is a non-default jj workspace.

func MaterializeWipFromParent added in v1.9.51

func MaterializeWipFromParent(parentDir, workspacePath string, includeIgnored bool) error

MaterializeWipFromParent reproduces the parent workspace's uncommitted working-copy state inside workspacePath, which must be a freshly created jj workspace anchored at the parent's @- (see CreateWorkspaceAtRevision).

Because jj's working copy *is* a commit and untracked (non-ignored) files are auto-snapshotted into it, a single `jj restore --from <parent @>` carries both tracked edits and untracked files — no separate untracked-copy pass is needed (unlike git). Gitignored files are not part of @, so they are filesystem-copied only when includeIgnored is set.

Contract:

  • parentDir is treated read-only (no commit/describe/squash); only a snapshot of its working copy is taken when resolving @.
  • On a colocated jj repo (has .git), gitignored files are enumerated via git's exclude machinery from the parent workspace root. If git metadata is unavailable, ignored-file copy is a documented no-op.

func SupportsGitignoredCopy added in v1.9.51

func SupportsGitignoredCopy(dir string) bool

SupportsGitignoredCopy reports whether copyGitignoredFromParent could actually enumerate and copy gitignored files for a fork rooted at dir — i.e. whether dir resolves to a git worktree root (a colocated jj repo). A pure jj repo (or a linked jj workspace) has no such root, so a with-ignored fork would silently carry nothing; callers use this to emit a notice instead.

func WorkingCopyParentRevision added in v1.9.51

func WorkingCopyParentRevision(dir string) (string, error)

WorkingCopyParentRevision returns the commit id of @- — the committed parent of the working-copy commit. This is the anchor a with-state fork workspace is created at, so that the materialized working copy reads as uncommitted changes on top of it (mirroring git's "fork at parent HEAD, lay WIP on top").

func WorkingCopyRevision added in v1.9.51

func WorkingCopyRevision(dir string) (string, error)

WorkingCopyRevision returns the commit id of the working-copy commit (@) of the workspace rooted at dir.

It intentionally does NOT pass --ignore-working-copy: jj only snapshots the on-disk working copy into @ when a normal command runs, so resolving with the flag would return a stale @ and silently drop the parent's most recent uncommitted edits — exactly the state a with-state fork must carry.

Types

type JJBackend

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

func NewJJBackend

func NewJJBackend(dir string) (*JJBackend, error)

func (*JJBackend) BranchExists

func (b *JJBackend) BranchExists(branchName string) bool

BranchExists checks if a bookmark exists in the repository.

func (*JJBackend) CheckoutBranch

func (b *JJBackend) CheckoutBranch(branchName string) error

CheckoutBranch moves the working copy to a new change based on the given bookmark.

func (*JJBackend) CreateWorktree

func (b *JJBackend) CreateWorktree(workspacePath, branchName string) error

CreateWorktree creates a new jj workspace at the given path.

func (*JJBackend) DeleteBranch

func (b *JJBackend) DeleteBranch(branchName string, force bool) error

DeleteBranch deletes a bookmark.

func (*JJBackend) GetCurrentBranch

func (b *JJBackend) GetCurrentBranch() (string, error)

GetCurrentBranch returns the first bookmark of the current working-copy change.

func (*JJBackend) GetDefaultBranch

func (b *JJBackend) GetDefaultBranch() (string, error)

GetDefaultBranch returns the default branch name (checks for main/master bookmarks).

func (*JJBackend) GetWorktreeForBranch

func (b *JJBackend) GetWorktreeForBranch(branchName string) (string, error)

func (*JJBackend) HasUncommittedChanges

func (b *JJBackend) HasUncommittedChanges() (bool, error)

HasUncommittedChanges checks if the working copy has uncommitted changes.

func (*JJBackend) ListWorktrees

func (b *JJBackend) ListWorktrees() ([]vcs.Worktree, error)

ListWorktrees returns all workspaces for the repository.

func (*JJBackend) MergeBranch

func (b *JJBackend) MergeBranch(branchName string) error

MergeBranch creates a merge change combining the current change with the given bookmark.

func (*JJBackend) PruneWorktrees

func (b *JJBackend) PruneWorktrees() error

PruneWorktrees removes workspace entries whose directories no longer exist.

func (*JJBackend) RemoveWorktree

func (b *JJBackend) RemoveWorktree(workspacePath string, force bool) error

RemoveWorktree forgets a workspace and optionally removes its directory.

func (*JJBackend) RepoDir

func (b *JJBackend) RepoDir() string

RepoDir returns the root directory of the repository.

func (*JJBackend) Type

func (g *JJBackend) Type() vcs.Type

func (*JJBackend) WorktreePath

func (b *JJBackend) WorktreePath(opts vcs.WorktreePathOptions) string

WorktreePath generates a workspace path using the backend's repoDir. Delegates to the shared template logic in the git package (VCS-agnostic).

type Workspace

type Workspace struct {
	Name string
	Path string
}

Workspace represents a jj workspace parsed from `jj workspace list`.

Jump to

Keyboard shortcuts

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