vcs

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package vcs provides an abstraction layer over version control systems. It supports Jujutsu (JJ) as the primary VCS with automatic fallback to Git.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGitVersion

func GetGitVersion() (string, error)

GetGitVersion returns the installed Git version

func GetJJVersion

func GetJJVersion() (string, error)

GetJJVersion returns the installed JJ version

func GetVCSInfo

func GetVCSInfo(repoPath string) (hasJJ bool, hasGit bool, isColocated bool)

GetVCSInfo returns information about what VCS is available at the path

func IsColocated

func IsColocated(repoPath string) bool

IsColocated checks if the repository is a JJ+Git colocated repository

Types

type Bookmark

type Bookmark struct {
	// Name is the bookmark/branch name
	Name string
	// RevisionID is the revision this bookmark points to
	RevisionID string
	// IsRemote indicates if this is a remote tracking bookmark
	IsRemote bool
	// Upstream is the remote tracking bookmark (if any)
	Upstream string
}

Bookmark represents a named reference (branch in Git, bookmark in JJ)

type ChangeStrategy

type ChangeStrategy int

ChangeStrategy defines how to handle uncommitted changes during workspace switches

const (
	// KeepAsWIP keeps changes as a separate WIP revision (JJ) or stash (Git)
	KeepAsWIP ChangeStrategy = iota
	// BringAlong keeps changes as parent of new location (JJ) or stash pop (Git)
	BringAlong
	// Abandon discards uncommitted changes
	Abandon
)

func ParseChangeStrategy

func ParseChangeStrategy(s string) (ChangeStrategy, error)

ParseChangeStrategy converts a string to ChangeStrategy

func (ChangeStrategy) String

func (s ChangeStrategy) String() string

type DetectOptions

type DetectOptions struct {
	// Preference is the user's VCS preference
	Preference VCSPreference
}

DetectOptions configures VCS detection behavior

func DefaultDetectOptions

func DefaultDetectOptions() DetectOptions

DefaultDetectOptions returns the default detection options

type GitClient

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

GitClient implements the VCS interface for Git

func NewGitClient

func NewGitClient(repoPath string) *GitClient

NewGitClient creates a new Git client for the given repository path

func (*GitClient) AbandonChanges

func (g *GitClient) AbandonChanges() error

AbandonChanges discards all uncommitted changes

func (*GitClient) CreateBookmark

func (g *GitClient) CreateBookmark(name string, base string) error

CreateBookmark creates a new branch at the specified base

func (*GitClient) CreateWorktree

func (g *GitClient) CreateWorktree(path string, branch string) error

CreateWorktree creates a new Git worktree

func (*GitClient) DescribeWIP

func (g *GitClient) DescribeWIP(message string) error

DescribeWIP is a no-op for Git (changes are always in working tree)

func (*GitClient) GetCurrentBookmark

func (g *GitClient) GetCurrentBookmark() (string, error)

GetCurrentBookmark returns the current branch name

func (*GitClient) GetCurrentRevision

func (g *GitClient) GetCurrentRevision() (*Revision, error)

GetCurrentRevision returns the current revision

func (*GitClient) GetStatus

func (g *GitClient) GetStatus() (*WorkingCopyStatus, error)

GetStatus returns the working copy status

func (*GitClient) HasUncommittedChanges

func (g *GitClient) HasUncommittedChanges() (bool, error)

HasUncommittedChanges checks if there are uncommitted changes

func (*GitClient) ListBookmarks

func (g *GitClient) ListBookmarks() ([]Bookmark, error)

ListBookmarks returns all branches

func (*GitClient) ListRecentRevisions

func (g *GitClient) ListRecentRevisions(limit int) ([]Revision, error)

ListRecentRevisions returns recent commits

func (*GitClient) ListWorktrees

func (g *GitClient) ListWorktrees() ([]Worktree, error)

ListWorktrees returns all Git worktrees

func (*GitClient) RepoPath

func (g *GitClient) RepoPath() string

RepoPath returns the repository path

func (*GitClient) SwitchTo

func (g *GitClient) SwitchTo(target string, opts SwitchOptions) error

SwitchTo switches to the target branch or commit

func (*GitClient) Type

func (g *GitClient) Type() VCSType

Type returns the VCS type

type JJClient

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

JJClient implements the VCS interface for Jujutsu

func NewJJClient

func NewJJClient(repoPath string) *JJClient

NewJJClient creates a new JJ client for the given repository path

func (*JJClient) AbandonChanges

func (j *JJClient) AbandonChanges() error

AbandonChanges abandons the current change

func (*JJClient) CreateBookmark

func (j *JJClient) CreateBookmark(name string, base string) error

CreateBookmark creates a new bookmark at the specified base

func (*JJClient) CreateWorktree

func (j *JJClient) CreateWorktree(path string, name string) error

CreateWorktree creates a new JJ workspace (worktree equivalent)

func (*JJClient) DescribeWIP

func (j *JJClient) DescribeWIP(message string) error

DescribeWIP sets the description for the current change

func (*JJClient) GetCurrentBookmark

func (j *JJClient) GetCurrentBookmark() (string, error)

GetCurrentBookmark returns the current bookmark name

func (*JJClient) GetCurrentRevision

func (j *JJClient) GetCurrentRevision() (*Revision, error)

GetCurrentRevision returns the current revision

func (*JJClient) GetStatus

func (j *JJClient) GetStatus() (*WorkingCopyStatus, error)

GetStatus returns the working copy status

func (*JJClient) HasUncommittedChanges

func (j *JJClient) HasUncommittedChanges() (bool, error)

HasUncommittedChanges checks if there are uncommitted changes

func (*JJClient) ListBookmarks

func (j *JJClient) ListBookmarks() ([]Bookmark, error)

ListBookmarks returns all bookmarks

func (*JJClient) ListRecentRevisions

func (j *JJClient) ListRecentRevisions(limit int) ([]Revision, error)

ListRecentRevisions returns recent revisions

func (*JJClient) ListWorktrees

func (j *JJClient) ListWorktrees() ([]Worktree, error)

ListWorktrees returns all JJ workspaces

func (*JJClient) RepoPath

func (j *JJClient) RepoPath() string

RepoPath returns the repository path

func (*JJClient) SwitchTo

func (j *JJClient) SwitchTo(target string, opts SwitchOptions) error

SwitchTo switches to the target revision or bookmark

func (*JJClient) Type

func (j *JJClient) Type() VCSType

Type returns the VCS type

type Revision

type Revision struct {
	// ID is the unique identifier (commit SHA in Git, change ID in JJ)
	ID string
	// ShortID is a shortened version of the ID for display
	ShortID string
	// Description is the commit/change message (first line)
	Description string
	// Author is the revision author
	Author string
	// Timestamp is when the revision was created
	Timestamp time.Time
	// Bookmarks are the bookmarks/branches pointing to this revision
	Bookmarks []string
	// IsCurrent indicates if this is the current working copy revision
	IsCurrent bool
}

Revision represents a VCS revision (commit in Git, change in JJ)

type SwitchOptions

type SwitchOptions struct {
	// ChangeStrategy determines how to handle uncommitted changes
	ChangeStrategy ChangeStrategy
	// CreateIfMissing creates the bookmark/branch if it doesn't exist
	CreateIfMissing bool
	// BaseRevision is the base for new bookmark creation (empty = current)
	BaseRevision string
}

SwitchOptions configures how to handle a workspace switch

type VCS

type VCS interface {
	// Type returns the VCS type (jj or git)
	Type() VCSType

	// RepoPath returns the root path of the repository
	RepoPath() string

	// GetStatus returns the working copy status
	GetStatus() (*WorkingCopyStatus, error)

	// HasUncommittedChanges returns true if there are uncommitted changes
	HasUncommittedChanges() (bool, error)

	// GetCurrentRevision returns the current revision
	GetCurrentRevision() (*Revision, error)

	// GetCurrentBookmark returns the current bookmark/branch name (may be empty)
	GetCurrentBookmark() (string, error)

	// SwitchTo switches to the target revision or bookmark
	SwitchTo(target string, opts SwitchOptions) error

	// CreateBookmark creates a new bookmark/branch
	CreateBookmark(name string, base string) error

	// DescribeWIP describes the current change as WIP (JJ: describe, Git: no-op)
	DescribeWIP(message string) error

	// AbandonChanges abandons uncommitted changes
	AbandonChanges() error

	// ListBookmarks returns all bookmarks/branches
	ListBookmarks() ([]Bookmark, error)

	// ListRecentRevisions returns recent revisions for display
	ListRecentRevisions(limit int) ([]Revision, error)

	// CreateWorktree creates a new worktree at the specified path
	CreateWorktree(path string, bookmark string) error

	// ListWorktrees returns all worktrees
	ListWorktrees() ([]Worktree, error)
}

VCS is the abstraction interface over JJ and Git operations

func Detect

func Detect(repoPath string) (VCS, error)

Detect detects and returns the appropriate VCS client for the given repository path. It respects user preferences and falls back appropriately.

func DetectWithOptions

func DetectWithOptions(repoPath string, opts DetectOptions) (VCS, error)

DetectWithOptions detects VCS with custom options

type VCSPreference

type VCSPreference string

VCSPreference represents the user's preferred VCS

const (
	// PreferenceAuto automatically detects VCS (JJ preferred if available)
	PreferenceAuto VCSPreference = "auto"
	// PreferenceJJ forces JJ usage
	PreferenceJJ VCSPreference = "jj"
	// PreferenceGit forces Git usage
	PreferenceGit VCSPreference = "git"
)

type VCSType

type VCSType string

VCSType represents the version control system in use

const (
	VCSTypeJJ  VCSType = "jj"
	VCSTypeGit VCSType = "git"
)

type WorkingCopyStatus

type WorkingCopyStatus struct {
	// HasChanges indicates if there are uncommitted changes
	HasChanges bool
	// ModifiedFiles is the count of modified files
	ModifiedFiles int
	// AddedFiles is the count of newly added files
	AddedFiles int
	// DeletedFiles is the count of deleted files
	DeletedFiles int
	// ConflictedFiles is the count of files with conflicts
	ConflictedFiles int
}

WorkingCopyStatus represents the status of the working copy

type Worktree

type Worktree struct {
	// Path is the filesystem path to the worktree
	Path string
	// Name is the worktree name (JJ workspace name)
	Name string
	// Bookmark is the associated bookmark/branch
	Bookmark string
	// RevisionID is the current revision in this worktree
	RevisionID string
	// IsCurrent indicates if this is the current worktree
	IsCurrent bool
}

Worktree represents a working tree/workspace

Jump to

Keyboard shortcuts

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