pub struct GitRepo { /* private fields */ }Implementations§
Source§impl GitRepo
impl GitRepo
Sourcepub fn init<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn init<P: AsRef<Path>>(path: P) -> Result<Self>
Initialize a new git repository.
Sets the initial branch from git.default_branch in the global torii
config (default main) instead of libgit2’s hard-coded master.
Sourcepub fn sync_toriignore(&self) -> Result<()>
pub fn sync_toriignore(&self) -> Result<()>
Sync .toriignore (+ .toriignore.local) → .git/info/exclude so git
itself respects the patterns. Always force-excludes .toriignore.local
itself — local rules are machine-private and must never be committed.
Called automatically on open and before staging.
Sourcepub fn add_all(&self) -> Result<()>
pub fn add_all(&self) -> Result<()>
Add all changes to staging, respecting .toriignore.
0.7.7: .torii/ is treated as reserved internal state and is
never staged by -a, the same way git add . skips .git/.
Before 0.7.7 snapshots lived in .torii/snapshots/ inside the
working tree, and a follow-up torii save -am silently
absorbed the entire snapshot (one case in the wild was 681 MB
pushed to origin before the receiving end aborted with a zlib
stream error). Fix #1 in 0.7.7 moved snapshots out of the
working tree; this skip is the defense-in-depth so anything
else under .torii/ (config.json, mirrors.json) is also kept
out of -a. To stage a path under .torii/ deliberately,
pass it explicitly: torii save .torii/config.json -m "...".
Sourcepub fn unstage<P: AsRef<Path>>(&self, paths: &[P]) -> Result<()>
pub fn unstage<P: AsRef<Path>>(&self, paths: &[P]) -> Result<()>
Unstage paths — equivalent to git reset HEAD -- <paths> (or git rm --cached
for files that were never committed). Keeps files on disk.
Sourcepub fn unstage_all(&self) -> Result<()>
pub fn unstage_all(&self) -> Result<()>
Unstage all paths currently in the index.
Sourcepub fn commit_amend(&self, message: &str) -> Result<()>
pub fn commit_amend(&self, message: &str) -> Result<()>
Amend the previous commit
Sourcepub fn pull(&self) -> Result<()>
pub fn pull(&self) -> Result<()>
Pull from remote (fetch + fast-forward merge of current branch)
Push local tags to a remote, but only the ones that aren’t already in sync with what the remote advertises.
0.7.8: pre-fix this function pushed every local tag on every
torii sync --push. GitLab fires its workflow:rules on each tag
ref the remote sees in a push event — even when the tag OID is
identical to what was already there — so every release retriggered
CI pipelines for every historical tag (v0.7.0, v0.7.1, v0.7.2, …).
In the gitorii repo this was producing 4+ stale pipelines per
release that all eventually got canceled, plus wasted runner time
while they were queued.
The fix: do an ls-remote (libgit2’s Remote::list after
connect_auth), compare each local tag’s OID against the remote’s,
and push only the ones that differ (or don’t exist remotely).
One extra network round-trip in exchange for not retriggering N
pipelines per release. With force=true the comparison still
holds but the refspec gets a + prefix so rewritten tag OIDs
(e.g. after torii history reauthor --since ...) still go through.
Sourcepub fn get_current_branch(&self) -> Result<String>
pub fn get_current_branch(&self) -> Result<String>
Get current branch name
Sourcepub fn workdir(&self) -> Option<&Path>
pub fn workdir(&self) -> Option<&Path>
Absolute path of the work tree, when the repository isn’t bare.
Sourcepub fn remotes(&self) -> Result<Vec<(String, Option<String>)>>
pub fn remotes(&self) -> Result<Vec<(String, Option<String>)>>
Remote aliases configured in the repo, in config order, with their
fetch URLs (None when a remote has no URL).
Sourcepub fn remote_exists(&self, name: &str) -> bool
pub fn remote_exists(&self, name: &str) -> bool
Whether a remote alias with this name exists.
Sourcepub fn remote_url(&self, name: &str) -> Result<Option<String>>
pub fn remote_url(&self, name: &str) -> Result<Option<String>>
Fetch URL of a remote, when configured. Errors if the remote doesn’t exist.
Sourcepub fn remote_set_url(&self, name: &str, url: &str) -> Result<()>
pub fn remote_set_url(&self, name: &str, url: &str) -> Result<()>
Overwrite the URL of an existing remote alias.
Sourcepub fn remote_delete(&self, name: &str) -> Result<()>
pub fn remote_delete(&self, name: &str) -> Result<()>
Drop a remote alias (does not touch the platform side).
Sourcepub fn status(&self) -> Result<RepoStatus>
pub fn status(&self) -> Result<RepoStatus>
Collect repository status — branch, HEAD summary, remote tracking and per-file changes. Pure data: rendering lives with the callers (CLI, TUI, IDE).
Source§impl GitRepo
impl GitRepo
Sourcepub fn log(
&self,
count: Option<usize>,
oneline: bool,
graph: bool,
author: Option<&str>,
since: Option<&str>,
until: Option<&str>,
grep: Option<&str>,
stat: bool,
signatures: bool,
) -> Result<()>
pub fn log( &self, count: Option<usize>, oneline: bool, graph: bool, author: Option<&str>, since: Option<&str>, until: Option<&str>, grep: Option<&str>, stat: bool, signatures: bool, ) -> Result<()>
Show commit history
Sourcepub fn show_reflog(&self, count: usize) -> Result<()>
pub fn show_reflog(&self, count: usize) -> Result<()>
Show reflog (HEAD movement history)
Sourcepub fn rebase_with_todo(&self, base: &str, todo_file: &Path) -> Result<()>
pub fn rebase_with_todo(&self, base: &str, todo_file: &Path) -> Result<()>
Rebase with a pre-written todo file (no editor required).
Unix-only because it shells out to git rebase -i and needs a
real shell to invoke the GIT_SEQUENCE_EDITOR helper script.
Sourcepub fn rebase_interactive(&self, base: &str) -> Result<()>
pub fn rebase_interactive(&self, base: &str) -> Result<()>
Interactive rebase
Sourcepub fn rebase_root_interactive(&self) -> Result<()>
pub fn rebase_root_interactive(&self) -> Result<()>
Interactive rebase from the root commit (git rebase -i --root)
Sourcepub fn rebase_root_with_todo(&self, todo_file: &Path) -> Result<()>
pub fn rebase_root_with_todo(&self, todo_file: &Path) -> Result<()>
Rebase from the root commit using a pre-written todo file
Sourcepub fn rebase_continue(&self) -> Result<()>
pub fn rebase_continue(&self) -> Result<()>
Continue an in-progress rebase
Sourcepub fn rebase_abort(&self) -> Result<()>
pub fn rebase_abort(&self) -> Result<()>
Abort the current rebase
Sourcepub fn rebase_skip(&self) -> Result<()>
pub fn rebase_skip(&self) -> Result<()>
Skip current patch in rebase
Sourcepub fn list_branches(&self) -> Result<Vec<String>>
pub fn list_branches(&self) -> Result<Vec<String>>
List local branches
Sourcepub fn list_remote_branches(&self) -> Result<Vec<String>>
pub fn list_remote_branches(&self) -> Result<Vec<String>>
List remote branches
Sourcepub fn create_orphan_branch(&self, name: &str) -> Result<()>
pub fn create_orphan_branch(&self, name: &str) -> Result<()>
Create a new branch
Create an orphan branch — sets HEAD to refs/heads/
pub fn create_branch(&self, name: &str) -> Result<()>
Sourcepub fn delete_branch(&self, name: &str) -> Result<()>
pub fn delete_branch(&self, name: &str) -> Result<()>
Delete a branch
Sourcepub fn switch_branch(&self, name: &str) -> Result<()>
pub fn switch_branch(&self, name: &str) -> Result<()>
Switch to a branch
Sourcepub fn checkout_remote_branch(&self, remote_name: &str) -> Result<()>
pub fn checkout_remote_branch(&self, remote_name: &str) -> Result<()>
Checkout a remote branch — creates local tracking branch then switches to it
Sourcepub fn rewrite_history(&self, start_date: &str, end_date: &str) -> Result<()>
pub fn rewrite_history(&self, start_date: &str, end_date: &str) -> Result<()>
Rewrite commit history with new dates
Sourcepub fn remove_file_from_history(&self, file_path: &str) -> Result<()>
pub fn remove_file_from_history(&self, file_path: &str) -> Result<()>
Remove a file from the entire git history
Sourcepub fn clean_history(&self) -> Result<()>
pub fn clean_history(&self) -> Result<()>
Clean up repository (expire reflogs, remove stale backup refs)
Sourcepub fn verify_remote(&self) -> Result<()>
pub fn verify_remote(&self) -> Result<()>
Verify remote repository status
Sourcepub fn fetch_named(&self, name: &str) -> Result<()>
pub fn fetch_named(&self, name: &str) -> Result<()>
Fetch from a specific named remote. Errors with a helpful hint
listing configured remotes if the name is not in .git/config.
Sourcepub fn fetch_all(&self) -> Result<()>
pub fn fetch_all(&self) -> Result<()>
Fetch from every configured remote. Prints one line per remote with status, returns Err if any single remote failed (the others still get attempted before the error surfaces).
Sourcepub fn revert_commit(&self, commit_hash: &str) -> Result<()>
pub fn revert_commit(&self, commit_hash: &str) -> Result<()>
Revert a specific commit
Sourcepub fn reset_commit(&self, commit_hash: &str, mode: &str) -> Result<()>
pub fn reset_commit(&self, commit_hash: &str, mode: &str) -> Result<()>
Reset to a specific commit
Sourcepub fn merge_branch(&self, branch_name: &str) -> Result<()>
pub fn merge_branch(&self, branch_name: &str) -> Result<()>
Merge a branch into current branch
Sourcepub fn rebase_branch(&self, branch_name: &str) -> Result<()>
pub fn rebase_branch(&self, branch_name: &str) -> Result<()>
Rebase current branch onto another branch
Source§impl GitRepo
impl GitRepo
List all tags
Get tags as a vector (for internal use)
Sourcepub fn delete_tag(&self, name: &str) -> Result<()>
pub fn delete_tag(&self, name: &str) -> Result<()>
Delete a tag
Push tags to remote. When force is true, the refspec is prefixed
with + so the remote tag is replaced even if it already points at
a different commit — same semantics as git push --force-with-lease
/--force for tags, and matches the behaviour of --force on the
push_all_tags path.
Sourcepub fn cherry_pick(&self, commit_hash: &str) -> Result<()>
pub fn cherry_pick(&self, commit_hash: &str) -> Result<()>
Cherry-pick a commit
Sourcepub fn cherry_pick_continue(&self) -> Result<()>
pub fn cherry_pick_continue(&self) -> Result<()>
Continue cherry-pick after resolving conflicts
Sourcepub fn cherry_pick_abort(&self) -> Result<()>
pub fn cherry_pick_abort(&self) -> Result<()>
Abort cherry-pick
Source§impl GitRepo
impl GitRepo
Sourcepub fn extract_commit_signature(&self, target: &str) -> Result<CommitSignature>
pub fn extract_commit_signature(&self, target: &str) -> Result<CommitSignature>
Extract the GPG armor and signed payload from a commit. Errors with
ToriiError::RepoState when the commit carries no signature.
Sourcepub fn resolve_commit_range(&self, target: &str) -> Result<Vec<String>>
pub fn resolve_commit_range(&self, target: &str) -> Result<Vec<String>>
Resolve a <rev> or <from>..<to> spec to the commit OIDs it
covers (newest first, revwalk order). Public so callers can show
counts / ask for confirmation before a destructive pass.
Sourcepub fn preview_signatures(
&self,
target: &str,
key: &str,
gpg_program: Option<&str>,
) -> Result<Vec<(String, String)>>
pub fn preview_signatures( &self, target: &str, key: &str, gpg_program: Option<&str>, ) -> Result<Vec<(String, String)>>
Render the signature armor each commit in the range would get,
without rewriting anything. Returns (oid, armor) pairs.
Sourcepub fn sign_range(
&self,
target: &str,
key: &str,
gpg_program: Option<&str>,
) -> Result<SignOutcome>
pub fn sign_range( &self, target: &str, key: &str, gpg_program: Option<&str>, ) -> Result<SignOutcome>
Rewrite every commit in the range with a fresh gpgsig header and
move affected local branch tips onto the rewritten OIDs. Refuses to
run on a dirty work tree — rewriting history with uncommitted
changes makes the resulting state hard to reason about.