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 ¶
- type Git
- func (Git) Add(ctx context.Context, dir string, files []string) (string, error)
- func (Git) Commit(ctx context.Context, dir string, message string) (string, error)
- func (Git) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (Git) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)
- func (Git) DisplayName() string
- func (Git) IsClean(ctx context.Context, dir string) (bool, error)
- func (Git) Log(ctx context.Context, dir string, count int) (string, error)
- func (Git) Name() string
- func (Git) Status(ctx context.Context, dir string) (string, error)
- type Jujutsu
- func (Jujutsu) Add(ctx context.Context, dir string, files []string) (string, error)
- func (Jujutsu) Commit(ctx context.Context, dir string, message string) (string, error)
- func (Jujutsu) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (Jujutsu) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)
- func (Jujutsu) DisplayName() string
- func (Jujutsu) IsClean(ctx context.Context, dir string) (bool, error)
- func (Jujutsu) Log(ctx context.Context, dir string, count int) (string, error)
- func (Jujutsu) Name() string
- func (Jujutsu) Status(ctx context.Context, dir string) (string, error)
- type Mercurial
- func (Mercurial) Add(ctx context.Context, dir string, files []string) (string, error)
- func (Mercurial) Commit(ctx context.Context, dir string, message string) (string, error)
- func (Mercurial) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (Mercurial) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)
- func (Mercurial) DisplayName() string
- func (Mercurial) IsClean(ctx context.Context, dir string) (bool, error)
- func (Mercurial) Log(ctx context.Context, dir string, count int) (string, error)
- func (Mercurial) Name() string
- func (Mercurial) Status(ctx context.Context, dir string) (string, error)
- type Subversion
- func (Subversion) Add(ctx context.Context, dir string, files []string) (string, error)
- func (Subversion) Commit(ctx context.Context, dir string, message string) (string, error)
- func (Subversion) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (Subversion) Diff(ctx context.Context, dir string, cached bool, file string) (string, error)
- func (Subversion) DisplayName() string
- func (Subversion) IsClean(ctx context.Context, dir string) (bool, error)
- func (Subversion) Log(ctx context.Context, dir string, count int) (string, error)
- func (Subversion) Name() string
- func (Subversion) Status(ctx context.Context, dir string) (string, error)
- type VCS
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) CurrentBranch ¶
func (Git) DisplayName ¶
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) CurrentBranch ¶
func (Jujutsu) DisplayName ¶
type Mercurial ¶
type Mercurial struct{}
Mercurial implements VCS for Mercurial (hg) repositories.
func (Mercurial) CurrentBranch ¶
func (Mercurial) DisplayName ¶
type Subversion ¶
type Subversion struct{}
Subversion implements VCS for Subversion (svn) working copies.
func (Subversion) CurrentBranch ¶
func (Subversion) DisplayName ¶
func (Subversion) DisplayName() string
func (Subversion) Name ¶
func (Subversion) Name() string
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 ¶
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 ¶
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).