Documentation
¶
Overview ¶
Package core drives a git repository through lazygit's command layer (github.com/jesseduffield/lazygit/pkg/commands), for a UI to show and act on.
Index ¶
- Constants
- Variables
- func CommitColumn(row []Pipe) int16
- func GraphRows(commits []*models.Commit) [][]Pipe
- func HandleDaemon() bool
- func IsConflict(err error) bool
- type Config
- type Conflict
- type ConflictedFile
- type Credential
- type LineAction
- type Options
- type Pick
- type Pipe
- type PipeKind
- type Repo
- func (r *Repo) AbortOperation(st models.WorkingTreeState) error
- func (r *Repo) AddSubmodule(url, path string) error
- func (r *Repo) AddWorktree(path, base, branch string) error
- func (r *Repo) ApplyLines(f *models.File, diff string, indices []int, action LineAction) error
- func (r *Repo) ApplyUndo(s UndoStep, redo bool) error
- func (r *Repo) BranchCommits(b *models.Branch, limit int) ([]*models.Commit, [][]Pipe, error)
- func (r *Repo) Checkout(name string) error
- func (r *Repo) CheckoutRef(ref string) error
- func (r *Repo) CheckoutRemoteBranch(b *models.RemoteBranch) error
- func (r *Repo) CherryPick(commits []*models.Commit) error
- func (r *Repo) Close()
- func (r *Repo) Closing()
- func (r *Repo) Commit(summary, description string, amend bool) error
- func (r *Repo) CommitFileDiff(c *models.Commit, f *models.CommitFile) (string, error)
- func (r *Repo) CommitFiles(c *models.Commit) ([]*models.CommitFile, error)
- func (r *Repo) CommitMessage(c *models.Commit) (string, error)
- func (r *Repo) CommonDir() string
- func (r *Repo) Configure(c Config) error
- func (r *Repo) ContinueOperation(st models.WorkingTreeState) error
- func (r *Repo) CreateTag(name, ref, message string) error
- func (r *Repo) DeleteBranch(name string, force bool) error
- func (r *Repo) DeleteNestedRepository(f *models.File) error
- func (r *Repo) DeleteRemoteBranch(b *models.RemoteBranch) error
- func (r *Repo) DeleteTag(name string) error
- func (r *Repo) Discard(f *models.File) error
- func (r *Repo) DropCommit(commits []*models.Commit, i int) error
- func (r *Repo) DropCommits(commits []*models.Commit, lo, hi int) error
- func (r *Repo) Fetch() error
- func (r *Repo) FetchBackground() error
- func (r *Repo) FetchRemote(remote string) error
- func (r *Repo) FileDiff(f *models.File, staged bool) (string, error)
- func (r *Repo) FindUndo(redo bool) (UndoStep, error)
- func (r *Repo) FixupCommit(commits []*models.Commit, i int) error
- func (r *Repo) FixupCommits(commits []*models.Commit, lo, hi int) error
- func (r *Repo) Limit() int
- func (r *Repo) Load(background bool) (*Snapshot, error)
- func (r *Repo) MarkResolved(f *models.File) error
- func (r *Repo) Merge(name string) error
- func (r *Repo) MoveCommit(commits []*models.Commit, i, delta int) error
- func (r *Repo) MoveCommits(commits []*models.Commit, lo, hi, delta int) error
- func (r *Repo) Name() string
- func (r *Repo) NewBranch(name, base string) error
- func (r *Repo) Pull() error
- func (r *Repo) Push(head *models.Branch, remote string, force bool) error
- func (r *Repo) PushRemote(head *models.Branch) (remote string, ask bool, err error)
- func (r *Repo) PushTag(remote, name string) error
- func (r *Repo) ReadConflicted(path string) (string, error)
- func (r *Repo) RebaseOnto(name string) error
- func (r *Repo) RefCommits(fullRef string, limit int) ([]*models.Commit, [][]Pipe, error)
- func (r *Repo) RemoveSubmodule(s *Submodule) error
- func (r *Repo) RemoveWorktree(w *models.Worktree, force bool) error
- func (r *Repo) ResetTo(hash string, mode ResetMode) error
- func (r *Repo) ResolveConflict(f *models.File, expected, content string) (staged bool, err error)
- func (r *Repo) RewordCommit(commits []*models.Commit, i int, summary, description string) error
- func (r *Repo) SkipOperation(st models.WorkingTreeState) error
- func (r *Repo) StashAll(message string) error
- func (r *Repo) StashApply(e *models.StashEntry) error
- func (r *Repo) StashDrop(e *models.StashEntry) error
- func (r *Repo) StashFileDiff(e *models.StashEntry, f *models.CommitFile) (string, error)
- func (r *Repo) StashFiles(e *models.StashEntry) ([]*models.CommitFile, error)
- func (r *Repo) StashPop(e *models.StashEntry) error
- func (r *Repo) ToggleAllStaged(files []*models.File) error
- func (r *Repo) ToggleStaged(f *models.File) error
- func (r *Repo) Tr() *i18n.TranslationSet
- func (r *Repo) UpdateAllSubmodules() error
- func (r *Repo) UpdateSubmodule(s *Submodule) error
- func (r *Repo) WorktreePath(path string) string
- type ResetMode
- type Snapshot
- type Submodule
- type UndoKind
- type UndoStep
Constants ¶
const CommitLimit = 300
CommitLimit is how many commits a snapshot loads, unless configured otherwise.
const ReflogLimit = 300
ReflogLimit is how many entries of the reflog a snapshot loads.
Variables ¶
var ErrClosed = errors.New("the repository is closed")
ErrClosed is the error of a command of a repository closed.
var ErrNestedRepository = errors.New("it is a repository of its own, with its history")
ErrNestedRepository is the error of discarding a repository inside the work tree, which DeleteNestedRepository does, with all its history.
var ErrNotMerged = errors.New("the branch isn't fully merged")
ErrNotMerged is the error of deleting, without forcing, a branch whose commits no other branch has.
var ErrNotRegular = errors.New("not a regular file of the work tree")
ErrNotRegular is the error of reading or writing, as text, a conflicted path that isn't a regular file of the work tree, as a symlink: a repository's symlink could point anywhere.
var ErrStale = errors.New("the file changed since its diff was shown: look at it again")
ErrStale is the error of acting on a diff that is no longer the file's.
var ErrStashKept = errors.New("your local changes are kept in stash@{0}")
ErrStashKept wraps the error of an undo whose local changes, stashed around its reset, didn't apply again: they are in stash@{0}.
var ErrTooLarge = errors.New("the diff is too large to show here")
ErrTooLarge is the error of a diff larger than maxDiffSize.
var ErrWorktreeDirty = errors.New("the worktree has changes")
ErrWorktreeDirty is the error of removing, without forcing, a worktree with changes, which are lost with it.
Functions ¶
func CommitColumn ¶
CommitColumn is the column of a row's commit.
func HandleDaemon ¶
func HandleDaemon() bool
HandleDaemon runs the process as lazygit's daemon when git started it so, as the sequence editor of an interactive rebase, and reports whether it did. main must call it before anything else: lazygit's rebases re-run the app's own binary.
func IsConflict ¶
IsConflict reports whether err is git stopping on conflicts, as a merge, rebase, pull or cherry-pick does: known from the operation left in progress, or, for a stash applied, from git's words.
Types ¶
type Config ¶ added in v0.5.0
type Config struct {
// DiffContext is the lines of context around a diff's changes, 1 or
// more: line staging needs some.
DiffContext int
// CommitLimit is how many commits a snapshot loads.
CommitLimit int
// SignOff adds a Signed-off-by trailer to the commits made.
SignOff bool
// MainBranches are the branches whose commits count as merged, as
// master and main.
MainBranches []string
}
Config is what of the app's settings git's commands follow, which a repository takes in place of lazygit's config.yml.
func DefaultConfig ¶ added in v0.5.0
func DefaultConfig() Config
DefaultConfig is lazygit's defaults, and the app's limit.
func (Config) Normalized ¶ added in v0.5.0
Normalized holds a config to what the app can use.
type Conflict ¶
type Conflict struct {
Start, Base, Middle, End int
// OursLabel and TheirsLabel are what the markers say, as "HEAD" and
// "feature".
OursLabel, TheirsLabel string
}
Conflict is a conflict of a file: the indices of its marker lines, as lazygit finds them, Base -1 without the diff3 style.
type ConflictedFile ¶
ConflictedFile is a file with conflict markers, split into lines that keep their line endings.
func ParseConflicts ¶
func ParseConflicts(content string, markerSize int) *ConflictedFile
ParseConflicts finds the conflicts of a file's content, with lazygit's rules: markers of markerSize characters (7 when 0, the conflict-marker-size attribute otherwise), the start, base and end ones with an optional label after a space, the middle one alone.
func (*ConflictedFile) Resolve ¶
func (f *ConflictedFile) Resolve(i int, pick Pick) string
Resolve is the file's content with conflict i resolved by pick, the other conflicts left as they are.
func (*ConflictedFile) ResolveAll ¶
func (f *ConflictedFile) ResolveAll(pick Pick) string
ResolveAll is the file's content with every conflict resolved by pick.
type Credential ¶
type Credential = oscommands.CredentialType
Credential is what a command asks the user for.
type LineAction ¶
type LineAction int
LineAction is what ApplyLines does with the lines chosen of a diff.
const ( // StageLines puts lines of the unstaged diff into the index. StageLines LineAction = iota // UnstageLines takes lines of the staged diff out of the index. UnstageLines // DiscardLines throws lines of the unstaged diff away from the work tree. DiscardLines )
type Options ¶
type Options struct {
// ConfigDir holds lazygit's config.yml and state.yml for the app; empty
// keeps lazygit's own lookup (CONFIG_DIR, then lazygit's directory).
ConfigDir string
// OnCommand is told of each command about to run, from any goroutine.
OnCommand func(cmd string, commandLine bool)
// AskCredential asks for a username, password or passphrase a command
// waits on; the channel gives the answer. From any goroutine.
AskCredential func(kind Credential) <-chan string
}
Options are the hooks a UI gives a repository.
type Pipe ¶
type Pipe struct {
From, To int16
Kind PipeKind
// Color is the index of the pipe's color, from the commit it leaves.
Color uint8
// contains filtered or unexported fields
}
Pipe is a line of the graph through one row, between columns From (at the row's top, or its commit for Starts) and To (at its bottom, or its commit for Terminates).
type Repo ¶
type Repo struct {
// Path is the work tree's root.
Path string
// contains filtered or unexported fields
}
Repo is an open repository. Its methods run git and block; call them off the UI thread.
Several repositories can be open at once, one per window. lazygit's commands assume one repository per process, though: it changes the process's working directory and git's environment for it, and some of its file operations go by paths relative to the working directory. So the repositories take turns: one command runs at a time, in the whole process, with its repository current (see enter).
func Open ¶
Open opens the repository dir is in. lazygit's constructor changes the working directory and git's environment, so it takes its turn as commands do. It blocks: call it off the UI thread.
func (*Repo) AbortOperation ¶
func (r *Repo) AbortOperation(st models.WorkingTreeState) error
func (*Repo) AddSubmodule ¶ added in v0.4.0
AddSubmodule adds the repository at url as a submodule at path.
func (*Repo) AddWorktree ¶ added in v0.4.0
AddWorktree makes a worktree at path, checking out base, or, with branch, a new branch of that name from base.
func (*Repo) ApplyLines ¶
ApplyLines acts on some of the lines of a file's diff, as lazygit's staging does: diff is the text the lines were chosen in (FileDiff's), and indices are into patch.Parse(diff).Lines(). Lines that are not changes are ignored. Choosing every change acts on the whole file, as staging or unstaging it, so that an added or deleted file is added or deleted rather than emptied.
It acts only on the diff shown: when the file's diff is no longer diff, as after an edit since, it fails with ErrStale rather than act on lines the user hasn't seen.
func (*Repo) ApplyUndo ¶
ApplyUndo undoes (or redoes) a step FindUndo found, marking it in the reflog. A hard reset stashes the work tree's changes around it, as lazygit's does, and gives back only the stash it made; it refuses to overwrite files git doesn't track (untracked or ignored) where the target has files.
func (*Repo) BranchCommits ¶
BranchCommits loads the latest commits of a branch, with their graph.
func (*Repo) CheckoutRef ¶ added in v0.4.0
CheckoutRef checks out a tag or a commit, by its full name or hash, detaching the head.
func (*Repo) CheckoutRemoteBranch ¶ added in v0.4.0
func (r *Repo) CheckoutRemoteBranch(b *models.RemoteBranch) error
CheckoutRemoteBranch checks out the local branch of a remote branch's name, making it, tracking the remote one, when there is none.
func (*Repo) CherryPick ¶
CherryPick copies commits onto HEAD, given newest first as logs list them; they are applied oldest first.
func (*Repo) Close ¶
func (r *Repo) Close()
Close closes the repository: its commands fail from then on, and its temporary files are removed. It waits for a command running: call it off the UI thread.
func (*Repo) Closing ¶
func (r *Repo) Closing()
Closing marks the repository as about to close, at once: commands that haven't started fail from then on. Close closes it.
func (*Repo) Commit ¶
Commit commits what is staged. Amending adds it to the last commit, whose message becomes summary and description when summary is given.
func (*Repo) CommitFileDiff ¶
CommitFileDiff is the diff of a file a commit changes.
func (*Repo) CommitFiles ¶
CommitFiles lists the files a commit changes, against its first parent.
func (*Repo) CommonDir ¶ added in v0.5.2
CommonDir is the git directory a repository and its worktrees share, which tells the windows of one repository from those of another: their commits are the same objects.
func (*Repo) Configure ¶ added in v0.5.0
Configure makes the repository's commands follow c, from the next command on. It waits for a command running: call it off the UI thread.
func (*Repo) ContinueOperation ¶
func (r *Repo) ContinueOperation(st models.WorkingTreeState) error
ContinueOperation continues the merge, rebase, cherry-pick or revert in progress, skipping the editor for a commit's message; SkipOperation skips its current commit, and AbortOperation gives it up.
func (*Repo) CreateTag ¶ added in v0.4.0
CreateTag tags ref: an annotated tag with message, or a lightweight one without.
func (*Repo) DeleteBranch ¶
DeleteBranch deletes a branch: unless force, only one merged, failing with ErrNotMerged otherwise.
func (*Repo) DeleteNestedRepository ¶
DeleteNestedRepository deletes a repository inside the work tree that isn't a submodule, with all its history.
func (*Repo) DeleteRemoteBranch ¶ added in v0.4.0
func (r *Repo) DeleteRemoteBranch(b *models.RemoteBranch) error
DeleteRemoteBranch deletes a branch on its remote.
func (*Repo) DropCommits ¶ added in v0.3.0
DropCommits drops commits lo to hi of a log, newest first, in one interactive rebase. A merge is dropped only by itself: its todo is a merge line, not a pick to drop.
func (*Repo) FetchBackground ¶ added in v0.5.0
FetchBackground fetches, as lazygit does on its own every few minutes: without the command log, and failing rather than asking for a password.
func (*Repo) FetchRemote ¶ added in v0.4.0
FetchRemote fetches one remote.
func (*Repo) FileDiff ¶
FileDiff is the diff of a file of the work tree: its staged changes, or those not staged yet.
func (*Repo) FindUndo ¶
FindUndo finds the step undo (or redo) would take, walking the reflog as lazygit does: each undo counts one step back, each redo one forward.
func (*Repo) FixupCommit ¶
FixupCommit squashes a commit into the one below it, keeping that one's message.
func (*Repo) FixupCommits ¶ added in v0.3.0
FixupCommits squashes commits lo to hi of a log, newest first, into the one below them, keeping that one's message, in one interactive rebase.
func (*Repo) Load ¶
Load reads the repository's state. background marks a refresh the user didn't ask for, which takes no optional locks.
func (*Repo) MarkResolved ¶
MarkResolved stages a file whose conflicts are resolved: one without conflict markers, or a conflict git wrote no markers for.
func (*Repo) MoveCommits ¶ added in v0.3.0
MoveCommits moves commits lo to hi of a log, newest first, one place up (delta -1, newer) or down (delta 1), in one interactive rebase.
func (*Repo) Push ¶
Push pushes the branch checked out. One with no upstream yet is pushed to remote, which becomes its upstream (see PushRemote).
func (*Repo) PushRemote ¶ added in v0.3.0
PushRemote is the remote the first push of head, a branch with no upstream yet, goes to: its branch.<name>.pushRemote, the repository's remote.pushDefault, or its only remote. With several remotes and neither set, ask is true: the user chooses, remote (origin, or the first) being the one to offer. A setting that names no remote fails: git would push to it as a path or a URL, and going to another remote in its place isn't for the app to decide.
func (*Repo) ReadConflicted ¶
ReadConflicted reads a conflicted file of the work tree, failing with ErrNotRegular for one that isn't a regular file.
func (*Repo) RebaseOnto ¶
func (*Repo) RefCommits ¶ added in v0.4.0
RefCommits loads the latest commits of a ref, by its full name, as refs/tags/v1, with their graph.
func (*Repo) RemoveSubmodule ¶ added in v0.4.0
RemoveSubmodule removes a submodule: its entry, its work tree, and its repository in .git/modules.
func (*Repo) RemoveWorktree ¶ added in v0.4.0
RemoveWorktree removes a linked worktree: unless force, only one without changes, failing with ErrWorktreeDirty otherwise.
func (*Repo) ResetTo ¶ added in v0.4.0
ResetTo resets the branch checked out to a commit. A hard reset refuses to overwrite files git doesn't track, and changes git stash would pass over, as an undo's does; the changes to tracked files are lost, which the UI asks about.
func (*Repo) ResolveConflict ¶
ResolveConflict writes content, a resolution of the conflicted file f, in place of expected, the content it was resolved from. It fails with ErrStale when the file is no longer expected, as after an edit in another app since, rather than overwrite that. With no conflict left in content, the file is staged, as resolved; staged reports it.
func (*Repo) RewordCommit ¶
func (*Repo) SkipOperation ¶
func (r *Repo) SkipOperation(st models.WorkingTreeState) error
func (*Repo) StashApply ¶
func (r *Repo) StashApply(e *models.StashEntry) error
func (*Repo) StashFileDiff ¶
func (r *Repo) StashFileDiff(e *models.StashEntry, f *models.CommitFile) (string, error)
StashFileDiff is the diff of a file a stash entry changes.
func (*Repo) StashFiles ¶
func (r *Repo) StashFiles(e *models.StashEntry) ([]*models.CommitFile, error)
StashFiles lists the files a stash entry changes.
func (*Repo) StashPop ¶
func (r *Repo) StashPop(e *models.StashEntry) error
StashPop applies a stash entry, then drops it. Applying goes by the entry's commit, which nothing changes; dropping can only go by its index in the stash, which is checked again just before (see stashDo).
func (*Repo) ToggleAllStaged ¶
ToggleAllStaged stages every change, or unstages them all when all are staged already.
func (*Repo) Tr ¶
func (r *Repo) Tr() *i18n.TranslationSet
Tr is lazygit's English strings, as for a working tree state's title.
func (*Repo) UpdateAllSubmodules ¶ added in v0.4.0
UpdateAllSubmodules does UpdateSubmodule for every one.
func (*Repo) UpdateSubmodule ¶ added in v0.4.0
UpdateSubmodule initializes a submodule if need be, and checks out the commit the repository records for it.
func (*Repo) WorktreePath ¶ added in v0.4.0
WorktreePath is where a path typed for a new worktree goes: relative to the repository's work tree, so that "../app-fix" is beside it.
type ResetMode ¶ added in v0.4.0
type ResetMode string
ResetMode is how ResetTo resets: soft keeps the index and the work tree, mixed the work tree, hard neither.
type Snapshot ¶
type Snapshot struct {
Files []*models.File
Branches []*models.Branch
Commits []*models.Commit
Stash []*models.StashEntry
// Remotes have their branches.
Remotes []*models.Remote
Tags []*models.Tag
// Reflog is HEAD's, newest first, up to ReflogLimit entries.
Reflog []*models.Commit
Worktrees []*models.Worktree
Submodules []*Submodule
// Graph is the commit graph's rows, one per commit.
Graph [][]Pipe
// Head is the branch checked out, nil while the head is detached and
// there are no branches.
Head *models.Branch
// State is the operation in progress, as a rebase.
State models.WorkingTreeState
}
Snapshot is the state of a repository at one time. It is not changed after Load returns it.
type Submodule ¶ added in v0.4.0
type Submodule struct {
*models.SubmoduleConfig
// Status is git's: ' ' at the commit recorded, '-' not initialized,
// '+' at another commit, 'U' with merge conflicts.
Status byte
// Head is the commit checked out in it, or recorded for one not
// initialized.
Head string
}
Submodule is a submodule of the repository, as .gitmodules lists it, with its state as git submodule status tells it.
func (*Submodule) Initialized ¶ added in v0.4.0
Initialized reports whether the submodule's work tree is checked out.
type UndoKind ¶
type UndoKind int
UndoKind is what kind of thing a step of the reflog did.
const ( // UndoCommit is a commit, a reset or a pull: HEAD moved on its branch. UndoCommit UndoKind = iota // UndoRebase is a whole rebase, from its start to its finish or abort. UndoRebase // UndoCheckout is a checkout of another branch or commit. UndoCheckout // UndoMerge is a merge, undone, as a rebase, with a hard reset. UndoMerge )