Documentation
¶
Overview ¶
Package git is a narrow shell-out wrapper around the `git` binary. Every lore subcommand that touches git funnels through here so error handling and exit-code mapping live in one place.
Index ¶
- func AppendIgnoreEntry(path, entry string) error
- func CheckIgnore(workdir, path string) (bool, error)
- func CommitExists(repo, rev string) (bool, error)
- func GlobalExcludesPath() (string, error)
- func Init(dir string) error
- func ListTrackedUnder(workdir, relPath string) ([]string, error)
- func MergeFile(project, base, central []byte) ([]byte, bool, error)
- func RepoExcludePath(workdir string) (string, error)
- func RepoToplevel(workdir string) (string, error)
- func Run(workdir string, args ...string) (string, error)
- func StatusRaw(repo string, paths ...string) ([]byte, error)
- type Result
- type TreeEntry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendIgnoreEntry ¶
AppendIgnoreEntry appends entry to path on its own line. Creates the parent directory and the file if either is missing. If the file exists and does not end with a newline, prepends one so entry isn't concatenated onto the previous line.
func CheckIgnore ¶
CheckIgnore reports whether path is ignored by gitignore rules as seen from workdir. Lives outside Run because `git check-ignore`'s exit 1 is a normal "not ignored" answer rather than a failure; Run would map that to CodeGitNetwork.
Semantics of `git check-ignore -q <path>`:
- exit 0 -> path matches a gitignore rule -> (true, nil)
- exit 1 -> path does not match any gitignore rule -> (false, nil)
- exit 128 -> workdir is not inside a git repo -> (false, nil)
- other -> real failure -> (false, *lerr.Error{CodeGitNetwork})
The "not a git repo" case is folded into the not-ignored answer so callers (notably `lore add`'s gitignore precheck) surface the standard CodeRefusedSafety message and the "add it to your global .gitignore" hint, rather than a confusing CodeGitNetwork. Conservatively reporting "not ignored" preserves the safety property: a non-git project is only safe to onboard when its agent dir is globally gitignored anyway, since the user may later `git init` and commit.
A missing git binary maps to CodeSetupMissing for consistency with Run.
func CommitExists ¶
CommitExists reports whether rev resolves to a commit object.
func GlobalExcludesPath ¶
GlobalExcludesPath returns the path of the user's global gitignore. Resolution order:
- `core.excludesFile` from git's GLOBAL config scope only. Local repo config is intentionally NOT consulted: slice 4's picker labels this option "machine-wide", so honouring a per-repo `core.excludesFile` override here would mislead the user into writing a rule that doesn't apply elsewhere. System scope is also skipped; the picker is about the user's own global file.
- $XDG_CONFIG_HOME/git/ignore, when XDG_CONFIG_HOME is set.
- $HOME/.config/git/ignore.
Does not create the file. The caller writes via AppendIgnoreEntry, which creates parents and the file as needed.
func ListTrackedUnder ¶
ListTrackedUnder returns paths inside relPath that are tracked by the git repo containing workdir. Used by slice 3's safety gate: moving tracked content into central and replacing it with a symlink would silently rewrite git's view of the project, so `lore add` refuses when the agent dir contains any tracked file.
Semantics of `git ls-files -- <relPath>`:
- exit 0, empty stdout -> nothing tracked under relPath -> ([], nil)
- exit 0, paths emitted -> tracked files inside relPath -> (paths, nil)
- exit 128 -> workdir is not inside a git repo -> ([], nil)
- other -> real failure -> (nil, *lerr.Error{CodeGitNetwork})
The "not a git repo" case folds into an empty result, mirroring CheckIgnore's convention: a non-git project trivially has no tracked files, and the safety gate concerns itself with what git currently tracks rather than what the user might track later.
A missing git binary maps to CodeSetupMissing for consistency with Run and CheckIgnore.
func RepoExcludePath ¶
RepoExcludePath returns the absolute path to .git/info/exclude for the repo containing workdir. Uses `git rev-parse --git-path info/exclude` so worktrees (where .git is a file pointing into the main repo's worktrees/ directory) and submodules resolve correctly without us parsing the .git file ourselves.
func RepoToplevel ¶
RepoToplevel returns the absolute path to the worktree root that contains workdir. Refuses with CodeRefusedSafety when workdir is not inside a git repo: callers (slice 4's picker, slice 10's link) lean on this as their "is this a git project?" gate so they don't try to land a gitignore entry, an exclude rule, or a check-ignore in a directory that has no git at all.
Used over a bare `git rev-parse --is-inside-work-tree` so the caller also gets the toplevel path (needed by slice 4's TargetRepoGitignore option, which must write to the repo root's .gitignore even when the project is onboarded from a subdirectory of a monorepo).
Types ¶
type Result ¶
type Result struct {
Stdout []byte
Stderr []byte
ExitCode int
// contains filtered or unexported fields
}
Result is the unmodified output of a Git process.