pub trait RepoBackend {
Show 15 methods
// Required methods
fn path(&self) -> &str;
fn commits(&self) -> &[CommitInfo];
fn changed_files(&self, index: usize) -> Vec<FileChange>;
fn commit_diff(&self, index: usize) -> Diff;
fn file_diff(&self, index: usize, path: &str) -> Diff;
fn working_status(&self, amend: bool) -> WorkingStatus;
fn working_diff(&self, path: &str, staged: bool, amend: bool) -> Diff;
fn stage(&self, path: &str) -> Result<(), String>;
fn unstage(&self, path: &str, amend: bool) -> Result<(), String>;
fn revert(&self, path: &str) -> Result<(), String>;
fn delete_untracked(&self, path: &str) -> Result<(), String>;
fn commit(&self, message: &str, amend: bool) -> Result<(), String>;
fn head_message(&self) -> Option<String>;
// Provided methods
fn apply_to_index(&self, patch: &str) -> Result<(), String> { ... }
fn signature(&self) -> Option<(String, String)> { ... }
}Expand description
The interface the UI layer depends on. Implemented by the live
Git2Backend and the in-memory FixtureBackend.
Required Methods§
Sourcefn commits(&self) -> &[CommitInfo]
fn commits(&self) -> &[CommitInfo]
All commits, newest first (reverse-topological, like git log).
Sourcefn changed_files(&self, index: usize) -> Vec<FileChange>
fn changed_files(&self, index: usize) -> Vec<FileChange>
Files changed by the commit at index, against its first parent.
Sourcefn commit_diff(&self, index: usize) -> Diff
fn commit_diff(&self, index: usize) -> Diff
Unified diff of the whole commit against its first parent.
Sourcefn file_diff(&self, index: usize, path: &str) -> Diff
fn file_diff(&self, index: usize, path: &str) -> Diff
Unified diff for a single file within the commit.
Sourcefn working_status(&self, amend: bool) -> WorkingStatus
fn working_status(&self, amend: bool) -> WorkingStatus
The current working-tree status: staged and unstaged changes.
When amend is set the staged side is computed against HEAD’s
parent instead of HEAD, so the changes already in the last commit
show up as staged (they will be part of the amended commit) and can be
unstaged to drop them — exactly how git gui’s amend mode behaves.
Sourcefn working_diff(&self, path: &str, staged: bool, amend: bool) -> Diff
fn working_diff(&self, path: &str, staged: bool, amend: bool) -> Diff
Diff for a single working-tree path. With staged false this is the
working copy against the index (git diff); with staged true it is
the index against the staged base — HEAD normally, HEAD’s parent
when amend is set.
Sourcefn stage(&self, path: &str) -> Result<(), String>
fn stage(&self, path: &str) -> Result<(), String>
Stage a path (git add <path>), staging a deletion if the file is
gone from the working tree. Returns a human-readable error on failure.
Sourcefn unstage(&self, path: &str, amend: bool) -> Result<(), String>
fn unstage(&self, path: &str, amend: bool) -> Result<(), String>
Unstage a path. Normally resets the index entry to HEAD
(git reset HEAD -- <path>); when amend is set it resets to HEAD’s
parent, removing the path’s change from the commit being amended.
Sourcefn revert(&self, path: &str) -> Result<(), String>
fn revert(&self, path: &str) -> Result<(), String>
Revert (discard) the unstaged working-tree changes to path, restoring
the working copy from the index — git checkout -- <path>, the
destructive half of git gui’s “Revert Changes”. Only the
working-vs-index delta is dropped; any staged changes to the same path
are preserved. Untracked files have no index entry to restore from; use
delete_untracked for those.
Sourcefn delete_untracked(&self, path: &str) -> Result<(), String>
fn delete_untracked(&self, path: &str) -> Result<(), String>
Delete an untracked file from the working tree. This is the “revert” a
brand-new file gets: it isn’t in the index or HEAD, so the only way to
undo its appearance is to remove it. The content is gone for good — git
never had a copy. The caller is responsible for only passing untracked
paths.
Sourcefn commit(&self, message: &str, amend: bool) -> Result<(), String>
fn commit(&self, message: &str, amend: bool) -> Result<(), String>
Commit the staged changes with message. When amend is set, replace
the current HEAD commit instead of adding a new one.
Sourcefn head_message(&self) -> Option<String>
fn head_message(&self) -> Option<String>
The full message of the current HEAD commit, used to pre-fill the
editor when amending. None if there is no commit yet.
Provided Methods§
Sourcefn apply_to_index(&self, patch: &str) -> Result<(), String>
fn apply_to_index(&self, patch: &str) -> Result<(), String>
Apply a unified-diff patch directly to the index (git apply --cached),
the mechanism behind partial (line-range) staging and unstaging. The
patch is always oriented to apply forward to the current index — the
stage-vs-unstage direction is baked in by
build_partial_patch. The default
implementation rejects it; backends that can model partial application
override it.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".