Skip to main content

GitRepo

Struct GitRepo 

Source
pub struct GitRepo { /* private fields */ }

Implementations§

Source§

impl GitRepo

Source

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.

Source

pub fn open<P: AsRef<Path>>(path: P) -> Result<Self>

Open an existing repository

Source

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.

Source

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 "...".

Source

pub fn add<P: AsRef<Path>>(&self, paths: &[P]) -> Result<()>

Add specific files to staging

Source

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.

Source

pub fn unstage_all(&self) -> Result<()>

Unstage all paths currently in the index.

Source

pub fn commit(&self, message: &str) -> Result<()>

Commit changes

Source

pub fn commit_amend(&self, message: &str) -> Result<()>

Amend the previous commit

Source

pub fn pull(&self) -> Result<()>

Pull from remote (fetch + fast-forward merge of current branch)

Source

pub fn push(&self, force: bool) -> Result<()>

Push to remote

Source

pub fn push_all_tags(&self, remote_name: &str, force: bool) -> Result<()>

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.

Source

pub fn get_current_branch(&self) -> Result<String>

Get current branch name

Source

pub fn workdir(&self) -> Option<&Path>

Absolute path of the work tree, when the repository isn’t bare.

Source

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).

Source

pub fn remote_exists(&self, name: &str) -> bool

Whether a remote alias with this name exists.

Source

pub fn remote_url(&self, name: &str) -> Result<Option<String>>

Fetch URL of a remote, when configured. Errors if the remote doesn’t exist.

Source

pub fn remote_add(&self, name: &str, url: &str) -> Result<()>

Register a new remote alias.

Source

pub fn remote_set_url(&self, name: &str, url: &str) -> Result<()>

Overwrite the URL of an existing remote alias.

Source

pub fn remote_delete(&self, name: &str) -> Result<()>

Drop a remote alias (does not touch the platform side).

Source

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

Source

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

Source

pub fn show_reflog(&self, count: usize) -> Result<()>

Show reflog (HEAD movement history)

Source

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.

Source

pub fn rebase_interactive(&self, base: &str) -> Result<()>

Interactive rebase

Source

pub fn rebase_root_interactive(&self) -> Result<()>

Interactive rebase from the root commit (git rebase -i --root)

Source

pub fn rebase_root_with_todo(&self, todo_file: &Path) -> Result<()>

Rebase from the root commit using a pre-written todo file

Source

pub fn rebase_continue(&self) -> Result<()>

Continue an in-progress rebase

Source

pub fn rebase_abort(&self) -> Result<()>

Abort the current rebase

Source

pub fn rebase_skip(&self) -> Result<()>

Skip current patch in rebase

Source

pub fn diff(&self, staged: bool, last: bool) -> Result<()>

Show changes

Source

pub fn list_branches(&self) -> Result<Vec<String>>

List local branches

Source

pub fn list_remote_branches(&self) -> Result<Vec<String>>

List remote branches

Source

pub fn create_orphan_branch(&self, name: &str) -> Result<()>

Create a new branch Create an orphan branch — sets HEAD to refs/heads/ without any parent. The next commit will be a new root. Index and working tree are left intact so the user can stage what they want before the first commit.

Source

pub fn create_branch(&self, name: &str) -> Result<()>

Source

pub fn delete_branch(&self, name: &str) -> Result<()>

Delete a branch

Source

pub fn switch_branch(&self, name: &str) -> Result<()>

Switch to a branch

Source

pub fn checkout_remote_branch(&self, remote_name: &str) -> Result<()>

Checkout a remote branch — creates local tracking branch then switches to it

Source

pub fn clone_repo(url: &str, directory: Option<&str>) -> Result<()>

Clone a repository

Source

pub fn rename_branch(&self, old_name: &str, new_name: &str) -> Result<()>

Rename a branch

Source

pub fn rewrite_history(&self, start_date: &str, end_date: &str) -> Result<()>

Rewrite commit history with new dates

Source

pub fn remove_file_from_history(&self, file_path: &str) -> Result<()>

Remove a file from the entire git history

Source

pub fn clean_history(&self) -> Result<()>

Clean up repository (expire reflogs, remove stale backup refs)

Source

pub fn verify_remote(&self) -> Result<()>

Verify remote repository status

Source

pub fn fetch(&self) -> Result<()>

Fetch from remote without merging

Source

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.

Source

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).

Source

pub fn revert_commit(&self, commit_hash: &str) -> Result<()>

Revert a specific commit

Source

pub fn reset_commit(&self, commit_hash: &str, mode: &str) -> Result<()>

Reset to a specific commit

Source

pub fn merge_branch(&self, branch_name: &str) -> Result<()>

Merge a branch into current branch

Source

pub fn rebase_branch(&self, branch_name: &str) -> Result<()>

Rebase current branch onto another branch

Source

pub fn ls(&self, path_filter: Option<&str>) -> Result<()>

List all tracked files in the index

Source

pub fn show(&self, object: Option<&str>) -> Result<()>

Show details of a commit, tag, or file at a given ref

Source§

impl GitRepo

Source

pub fn create_tag(&self, name: &str, message: Option<&str>) -> Result<()>

Create a tag

Source

pub fn list_tags(&self) -> Result<()>

List all tags

Source

pub fn get_tags_list(&self) -> Result<Vec<String>>

Get tags as a vector (for internal use)

Source

pub fn delete_tag(&self, name: &str) -> Result<()>

Delete a tag

Source

pub fn push_tags(&self, name: Option<&str>, force: bool) -> Result<()>

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.

Source

pub fn show_tag(&self, name: &str) -> Result<()>

Show tag details

Source

pub fn cherry_pick(&self, commit_hash: &str) -> Result<()>

Cherry-pick a commit

Source

pub fn cherry_pick_continue(&self) -> Result<()>

Continue cherry-pick after resolving conflicts

Source

pub fn cherry_pick_abort(&self) -> Result<()>

Abort cherry-pick

Source

pub fn blame(&self, file: &str, lines: Option<&str>) -> Result<()>

Show blame for a file

Source§

impl GitRepo

Source

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.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more