pub struct GitRepo { /* private fields */ }Implementations§
Source§impl GitRepo
impl GitRepo
pub fn discover() -> Result<Self>
pub fn root(&self) -> &PathBuf
pub fn has_staged_changes(&self) -> Result<bool>
pub fn has_any_changes(&self) -> Result<bool>
pub fn has_head(&self) -> Result<bool>
pub fn reset_head(&self) -> Result<()>
pub fn stage_file(&self, file: &str) -> Result<bool>
pub fn has_staged_after_add(&self) -> Result<bool>
pub fn commit(&self, message: &str) -> Result<()>
pub fn recent_commits(&self, count: usize) -> Result<String>
pub fn diff_cached(&self) -> Result<String>
pub fn diff_cached_stat(&self) -> Result<String>
pub fn diff_head(&self) -> Result<String>
pub fn status_porcelain(&self) -> Result<String>
pub fn untracked_files(&self) -> Result<String>
pub fn show(&self, rev: &str) -> Result<String>
pub fn log_range(&self, base: &str, count: Option<usize>) -> Result<String>
pub fn diff_range(&self, base: &str) -> Result<String>
pub fn current_branch(&self) -> Result<String>
pub fn head_short(&self) -> Result<String>
Sourcepub fn commits_since_last_tag(&self) -> Result<usize>
pub fn commits_since_last_tag(&self) -> Result<usize>
Count commits since the last tag. If no tags exist, counts all commits.
Sourcepub fn log_detailed(&self, count: usize) -> Result<String>
pub fn log_detailed(&self, count: usize) -> Result<String>
Get detailed log of recent commits (SHA, subject, body) oldest first.
pub fn file_statuses(&self) -> Result<HashMap<String, char>>
Sourcepub fn snapshot_working_tree(&self) -> Result<PathBuf>
pub fn snapshot_working_tree(&self) -> Result<PathBuf>
Create a snapshot of the working tree state into the platform data directory.
Location: <data_local_dir>/sr/snapshots/<repo-hash>/
- macOS: ~/Library/Application Support/sr/snapshots/
/ - Linux: ~/.local/share/sr/snapshots/
/ - Windows: %LOCALAPPDATA%/sr/snapshots/
/
The snapshot directly copies every changed/added/deleted file into
files/ alongside a manifest.json that records each file’s status
and whether it was staged. This avoids git-stash entirely — restore
is a plain file copy that cannot conflict.
Lives completely outside the repo so the agent cannot touch it.
Sourcepub fn restore_snapshot(&self) -> Result<()>
pub fn restore_snapshot(&self) -> Result<()>
Restore working tree from the latest snapshot.
- Reset HEAD to the original commit (undoes any partial commits)
- Clean the index
- Copy every snapshotted file back from
files/ - Delete files that were deleted at snapshot time
- Re-stage files that were staged at snapshot time
This is a plain file copy — no git-stash, no merge conflicts.
Sourcepub fn clear_snapshot(&self)
pub fn clear_snapshot(&self)
Remove the snapshot after a successful operation.
Sourcepub fn snapshot_dir(&self) -> Result<PathBuf>
pub fn snapshot_dir(&self) -> Result<PathBuf>
Returns the snapshot directory path for this repo.
Sourcepub fn has_snapshot(&self) -> bool
pub fn has_snapshot(&self) -> bool
Check if a valid snapshot exists.