vcs

package
v1.3.126 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package vcs provides a unified abstraction over multiple version control systems (git, Mercurial, Subversion, Jujutsu). It auto-detects the VCS in a working directory and dispatches operations through a common interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Git

type Git struct{}

Git implements VCS for git repositories.

func (Git) Add

func (Git) Add(ctx context.Context, dir string, files []string) (string, error)

func (Git) Commit

func (Git) Commit(ctx context.Context, dir string, message string) (string, error)

func (Git) CurrentBranch

func (Git) CurrentBranch(ctx context.Context, dir string) (string, error)

func (Git) Diff

func (Git) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)

func (Git) DisplayName

func (Git) DisplayName() string

func (Git) IsClean

func (Git) IsClean(ctx context.Context, dir string) (bool, error)

func (Git) Log

func (Git) Log(ctx context.Context, dir string, count int) (string, error)

func (Git) Name

func (Git) Name() string

func (Git) Status

func (Git) Status(ctx context.Context, dir string) (string, error)

type Jujutsu

type Jujutsu struct{}

Jujutsu implements VCS for Jujutsu (jj) repositories. jj often coexists with git; Detect returns jj only when .jj exists without .git.

jj's model differs from git: the working copy is always a commit (a "change"). Files are tracked automatically — there's no staging area. "Committing" means describing the current change and then creating a new empty change on top.

func (Jujutsu) Add

func (Jujutsu) Add(ctx context.Context, dir string, files []string) (string, error)

func (Jujutsu) Commit

func (Jujutsu) Commit(ctx context.Context, dir string, message string) (string, error)

func (Jujutsu) CurrentBranch

func (Jujutsu) CurrentBranch(ctx context.Context, dir string) (string, error)

func (Jujutsu) Diff

func (Jujutsu) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)

func (Jujutsu) DisplayName

func (Jujutsu) DisplayName() string

func (Jujutsu) IsClean

func (Jujutsu) IsClean(ctx context.Context, dir string) (bool, error)

func (Jujutsu) Log

func (Jujutsu) Log(ctx context.Context, dir string, count int) (string, error)

func (Jujutsu) Name

func (Jujutsu) Name() string

func (Jujutsu) Status

func (Jujutsu) Status(ctx context.Context, dir string) (string, error)

type Mercurial

type Mercurial struct{}

Mercurial implements VCS for Mercurial (hg) repositories.

func (Mercurial) Add

func (Mercurial) Add(ctx context.Context, dir string, files []string) (string, error)

func (Mercurial) Commit

func (Mercurial) Commit(ctx context.Context, dir string, message string) (string, error)

func (Mercurial) CurrentBranch

func (Mercurial) CurrentBranch(ctx context.Context, dir string) (string, error)

func (Mercurial) Diff

func (Mercurial) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)

func (Mercurial) DisplayName

func (Mercurial) DisplayName() string

func (Mercurial) IsClean

func (Mercurial) IsClean(ctx context.Context, dir string) (bool, error)

func (Mercurial) Log

func (Mercurial) Log(ctx context.Context, dir string, count int) (string, error)

func (Mercurial) Name

func (Mercurial) Name() string

func (Mercurial) Status

func (Mercurial) Status(ctx context.Context, dir string) (string, error)

type Subversion

type Subversion struct{}

Subversion implements VCS for Subversion (svn) working copies.

func (Subversion) Add

func (Subversion) Add(ctx context.Context, dir string, files []string) (string, error)

func (Subversion) Commit

func (Subversion) Commit(ctx context.Context, dir string, message string) (string, error)

func (Subversion) CurrentBranch

func (Subversion) CurrentBranch(ctx context.Context, dir string) (string, error)

func (Subversion) Diff

func (Subversion) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)

func (Subversion) DisplayName

func (Subversion) DisplayName() string

func (Subversion) IsClean

func (Subversion) IsClean(ctx context.Context, dir string) (bool, error)

func (Subversion) Log

func (Subversion) Log(ctx context.Context, dir string, count int) (string, error)

func (Subversion) Name

func (Subversion) Name() string

func (Subversion) Status

func (Subversion) Status(ctx context.Context, dir string) (string, error)

type VCS

type VCS interface {
	// Name returns the short identifier: "git", "hg", "svn", "jj".
	Name() string

	// DisplayName returns a human-friendly name: "Git", "Mercurial", etc.
	DisplayName() string

	// Status returns the working-tree status as human-readable text.
	Status(ctx context.Context, dir string) (string, error)

	// Diff returns the diff. If cached is true, show staged changes only.
	// If file is non-empty, limit to that file.
	Diff(ctx context.Context, dir string, cached bool, file string) (string, error)

	// Log returns recent commit history. count limits the number of entries.
	Log(ctx context.Context, dir string, count int) (string, error)

	// Add stages the given files for commit.
	Add(ctx context.Context, dir string, files []string) (string, error)

	// Commit records a new commit with the given message.
	Commit(ctx context.Context, dir string, message string) (string, error)

	// CurrentBranch returns the current branch/bookmark/head name.
	CurrentBranch(ctx context.Context, dir string) (string, error)

	// IsClean reports whether the working tree has no uncommitted changes.
	IsClean(ctx context.Context, dir string) (bool, error)
}

VCS represents a version control system backend.

func Detect

func Detect(workingDir string) VCS

Detect identifies the VCS used in the given working directory by walking up the directory tree looking for well-known metadata directories/files. Returns nil if no known VCS is found.

func DetectOrGit

func DetectOrGit(workingDir string) VCS

DetectOrGit is like Detect but falls back to Git{} when no VCS is found, so that callers always get a non-nil VCS (commands will fail naturally if the directory is not actually a repo).

Jump to

Keyboard shortcuts

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