vcs

package
v0.4.18 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vcs integrates version-control systems with the editor: diff bases for gutter hunks, changed-file listings, and head names. Git is the only provider today. The Provider interface keeps the API explicit and pluggable

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGitCommand   = errors.New("git command failed")
	ErrGitBadStatus = errors.New("unparsable git status output")
	ErrGitBadBatch  = errors.New("unparsable git cat-file output")
)

Functions

This section is empty.

Types

type Differ

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

Differ tracks the hunks between a version-control base text and a live document text. Updates are debounced so rapid keystrokes coalesce into one diff

func NewDiffer

func NewDiffer(sides view.DiffSides, notify func()) *Differ

NewDiffer starts a differ for the given base and document text. notify is invoked from a background goroutine after every recompute

func (*Differ) Base

func (d *Differ) Base() core.Rope

Base returns the current diff base text

func (*Differ) Close

func (d *Differ) Close()

Close drops pending recomputes and stops publishing hunks

func (*Differ) Hunks

func (d *Differ) Hunks() []view.DiffHunk

Hunks returns a snapshot of the current hunks

func (*Differ) SetBase

func (d *Differ) SetBase(base core.Rope)

SetBase schedules a recompute against a new diff base text

func (*Differ) SetDoc

func (d *Differ) SetDoc(doc core.Rope)

SetDoc schedules a recompute against a new document text

type Git

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

Git reads HEAD and index contents through one long-running cat-file process per repository, and shells out to git for everything else

func (*Git) ChangedFiles

func (g *Git) ChangedFiles(cwd string) ([]view.FileChange, error)

ChangedFiles reports working-tree changes in cwd's repository, as absolute paths

func (*Git) Close added in v0.4.12

func (g *Git) Close()

Close stops the cat-file processes

func (*Git) DiffBase

func (g *Git) DiffBase(path string) ([]byte, error)

DiffBase returns the HEAD contents of path. No eol/ident smudge filtering is applied. A .gitattributes eol conversion may cause phantom diffs

func (*Git) Discard added in v0.4.1

func (g *Git) Discard(cwd, path string) error

Discard restores the working-tree state of path from the index. An untracked file has no index state to restore, so it is deleted instead

func (*Git) HeadID

func (g *Git) HeadID(path string) (string, error)

HeadID returns the full current HEAD revision

func (*Git) HeadName

func (g *Git) HeadName(path string) (string, error)

HeadName returns the current branch name, or a short commit hash when the head is detached

func (*Git) Ignore added in v0.4.1

func (g *Git) Ignore(cwd, path string) error

Ignore appends path to the repository's root .gitignore, anchored so it names that one file rather than every file sharing its name

func (*Git) IndexText added in v0.4.1

func (g *Git) IndexText(cwd, path string) ([]byte, error)

IndexText returns the staged blob for path, erroring when the file has no entry in the index

func (*Git) Stage added in v0.4.1

func (g *Git) Stage(cwd, path string) error

Stage adds the working-tree state of path to the staging area, recording an added, modified, or deleted file alike

func (*Git) Tracked added in v0.4.7

func (g *Git) Tracked(cwd, path string) bool

Tracked reports whether the repository containing cwd has path in its index

func (*Git) Unstage added in v0.4.1

func (g *Git) Unstage(cwd, path string) error

Unstage drops path from the staging area, leaving the working tree alone

type Provider

type Provider interface {
	// DiffBase returns the checked-in contents of path, the "base" text a diff of the working
	// copy is computed against
	DiffBase(path string) ([]byte, error)

	// HeadName returns a short display name for the current head, such as a branch name
	HeadName(path string) (string, error)

	// HeadID returns the exact current head revision
	HeadID(path string) (string, error)

	// ChangedFiles lists workspace files that differ from the head
	ChangedFiles(cwd string) ([]view.FileChange, error)

	// IndexText returns the staged contents of path
	IndexText(cwd, path string) ([]byte, error)

	// Stage adds the working-tree state of path to the staging area of the repository
	// containing cwd
	Stage(cwd, path string) error

	// Unstage drops path from that staging area, leaving the working tree
	Unstage(cwd, path string) error

	// Discard restores the working-tree state of path from the staging area, deleting the file
	// when it is untracked
	Discard(cwd, path string) error

	// Ignore adds path to the ignore list of its repository
	Ignore(cwd, path string) error

	// Tracked reports whether the repository containing cwd tracks path
	Tracked(cwd, path string) bool

	// Close releases any processes the provider keeps running
	Close()
}

Provider supplies diff bases and change information from one version-control system

type Session

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

Session owns a differ per open document and implements the editor's VersionControl seam over the version-control provider

func Attach

func Attach(e *view.Editor) *Session

Attach starts a version-control session for the editor, observing document lifecycle events and serving diff state

func (*Session) ChangedFiles

func (s *Session) ChangedFiles() ([]view.FileChange, error)

ChangedFiles lists workspace files that differ from the head, including an open document with unsaved changes

func (*Session) Close

func (s *Session) Close()

Close stops all differs and the provider's processes

func (*Session) DiffBase

func (s *Session) DiffBase(doc *view.Document) (string, bool)

DiffBase returns the version-control base text for the document

func (*Session) DiffHunks

func (s *Session) DiffHunks(doc *view.Document) []view.DiffHunk

DiffHunks returns the current hunks for the document, loading its diff base on first request for a buffer that was not open at startup

func (*Session) Discard added in v0.4.1

func (s *Session) Discard(path string) error

Discard restores the working-tree state of path from the staging area, deleting the file when version control does not track it

func (*Session) DocumentChanged

func (s *Session) DocumentChanged(doc *view.Document, _ view.DocumentChange)

DocumentChanged feeds the new document text to the differ

func (*Session) DocumentClosed

func (s *Session) DocumentClosed(doc *view.Document)

DocumentClosed stops and forgets the document's differ

func (*Session) DocumentOpened

func (s *Session) DocumentOpened(doc *view.Document)

DocumentOpened fetches the diff base in the background and starts a differ once it arrives

func (*Session) DocumentSaved

func (s *Session) DocumentSaved(doc *view.Document)

DocumentSaved refreshes the diff base. The head may have moved since the document was opened

func (*Session) HeadName

func (s *Session) HeadName(doc *view.Document) (string, bool)

HeadName returns the head display name for the document's repository

func (*Session) HeadText added in v0.4.1

func (s *Session) HeadText(path string) string

HeadText returns the head text of an arbitrary workspace file. It reads from the provider on every call, so it is intended for on-demand use such as picker previews

func (*Session) Ignore added in v0.4.1

func (s *Session) Ignore(path string) error

Ignore adds path to the ignore list of the repository holding it

func (*Session) IndexText added in v0.4.1

func (s *Session) IndexText(path string) string

IndexText returns the staged text of an arbitrary workspace file, falling back to its head text when the file has no entry in the index

func (*Session) Refresh

func (s *Session) Refresh()

Refresh reloads open document diff bases when their repository head moves. Reading a head forks git per document, so the check runs off the caller's goroutine

func (*Session) Stage added in v0.4.1

func (s *Session) Stage(path string) error

Stage adds the working-tree state of path to the staging area

func (*Session) StagedDiffHunks added in v0.4.1

func (s *Session) StagedDiffHunks(path string) []view.DiffHunk

StagedDiffHunks computes hunks between the head and the staged contents of an arbitrary workspace file. It reads both sides from the provider each call, so it is intended for on-demand use such as picker previews

func (*Session) Unstage added in v0.4.1

func (s *Session) Unstage(path string) error

Unstage drops path from the staging area, leaving the working tree

func (*Session) UnstagedDiffHunks added in v0.4.1

func (s *Session) UnstagedDiffHunks(path string) []view.DiffHunk

UnstagedDiffHunks computes hunks between the staged and current contents of a workspace file, preferring its open document over the copy on disk

func (*Session) Updates

func (s *Session) Updates() <-chan struct{}

Updates delivers a token whenever diff state changes

Jump to

Keyboard shortcuts

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