pub struct Repo { /* private fields */ }Implementations§
Source§impl Repo
impl Repo
Sourcepub fn discover(from: &Path) -> Option<Self>
pub fn discover(from: &Path) -> Option<Self>
Discover the repository containing path (buffer path or cwd).
pub fn workdir(&self) -> &Path
Sourcepub fn remotes(&self) -> Vec<(String, String)>
pub fn remotes(&self) -> Vec<(String, String)>
Remotes as (name, url) pairs — libgit2 config, no spawn.
Sourcepub fn head_sha(&self) -> Option<String>
pub fn head_sha(&self) -> Option<String>
HEAD’s full SHA (permalink base — branch always resolves to SHA).
Sourcepub fn head_branch(&self) -> Option<String>
pub fn head_branch(&self) -> Option<String>
Current branch (short name; detached HEAD gives the sha prefix).
Sourcepub fn head_bytes(&self, rel: &Path) -> Option<Vec<u8>>
pub fn head_bytes(&self, rel: &Path) -> Option<Vec<u8>>
HEAD’s content for path, if tracked.
HEAD’s blob bytes for a repo-relative path (typed, not lossy).
Sourcepub fn commit_bytes(&self, sha: &str, rel: &Path) -> Option<Vec<u8>>
pub fn commit_bytes(&self, sha: &str, rel: &Path) -> Option<Vec<u8>>
A commit’s blob bytes for a repo-relative path.
Sourcepub fn index_bytes(&self, rel: &Path) -> Option<Vec<u8>>
pub fn index_bytes(&self, rel: &Path) -> Option<Vec<u8>>
The index’s blob bytes for a repo-relative path (reloads — never a stale snapshot).
pub fn head_content(&self, path: &Path) -> Option<String>
Sourcepub fn index_content(&self, path: &Path) -> Option<String>
pub fn index_content(&self, path: &Path) -> Option<String>
The index’s content for path (the staged version), if any.
Sourcepub fn staged_hunks(&self, path: &Path) -> Vec<Hunk>
pub fn staged_hunks(&self, path: &Path) -> Vec<Hunk>
Hunks between HEAD and the index — the STAGED set (0014 wave 4: the four states are HEAD → index → worktree → live document, and every command names its edge).
Sourcepub fn unstaged_hunks(&self, path: &Path, content: &str) -> Vec<Hunk>
pub fn unstaged_hunks(&self, path: &Path, content: &str) -> Vec<Hunk>
Hunks between the index and content — the UNSTAGED set (what
the gutter shows while you edit). When nothing is staged this
equals HEAD↔content, matching pre-0.5 behavior.
Sourcepub fn unstage_hunk(&self, rel: &Path, hunk: &Hunk) -> Result<(), String>
pub fn unstage_hunk(&self, rel: &Path, hunk: &Hunk) -> Result<(), String>
Unstage one hunk, STRUCTURED (0018): the staged hunk’s new side is what’s in the index; swap that region for the old side.
Sourcepub fn hunks(&self, path: &Path, content: &str) -> Vec<Hunk>
pub fn hunks(&self, path: &Path, content: &str) -> Vec<Hunk>
Hunks between HEAD and content for path. Untracked files
report a single all-Add hunk.
Sourcepub fn commit_file_diff(
&self,
sha: &str,
path: &Path,
) -> Result<FileDiff, String>
pub fn commit_file_diff( &self, sha: &str, path: &Path, ) -> Result<FileDiff, String>
One file’s diff at sha vs its first parent, as structured
hunks. The delta view’s data (0010 §1) — libgit2, no shell-out,
no re-parsing our own text.
Sourcepub fn stage_hunk(&self, rel: &Path, hunk: &Hunk) -> Result<(), String>
pub fn stage_hunk(&self, rel: &Path, hunk: &Hunk) -> Result<(), String>
Stage one hunk, STRUCTURED (0018): read the index blob, swap the
hunk’s old-side region for its new-side lines, write the blob
back into the index. No patch serialization — path quoting,
CRLF, and missing-final-newline can’t go wrong because nothing
is serialized. rel is repo-relative.