pub struct GitModule { /* private fields */ }Expand description
Git module instance, tied to a Session.
Tracks which worktrees and branches were created by this session. Write operations check ownership before proceeding; read operations bypass the check entirely.
Implementations§
Source§impl GitModule
impl GitModule
Sourcepub fn status(&self) -> Result<StatusOutput>
pub fn status(&self) -> Result<StatusOutput>
Inspect the working tree and produce a StatusOutput split into
staged / unstaged / untracked buckets.
Sourcepub fn log(&self, max_count: usize) -> Result<LogOutput>
pub fn log(&self, max_count: usize) -> Result<LogOutput>
Walk HEAD back up to max_count commits.
Sourcepub fn diff(&self, staged: bool) -> Result<DiffOutput>
pub fn diff(&self, staged: bool) -> Result<DiffOutput>
Produce the patch for either the staged (HEAD vs index) or the
unstaged (index vs worktree) view, controlled by staged.
Sourcepub fn worktree_list(&self) -> Result<WorktreeListOutput>
pub fn worktree_list(&self) -> Result<WorktreeListOutput>
List every linked worktree, annotated with session-ownership.
Source§impl GitModule
impl GitModule
Sourcepub fn fetch(
&self,
remote: Option<&str>,
refspec: Option<&str>,
prune: bool,
) -> Result<FetchOutput>
pub fn fetch( &self, remote: Option<&str>, refspec: Option<&str>, prune: bool, ) -> Result<FetchOutput>
Fetch from a remote.
remote defaults to "origin". refspec is forwarded verbatim when
present. prune adds --prune so deleted upstream refs are removed
locally. The combined stdout + stderr is returned as raw for
transport diagnostics — successful fetches usually print nothing on
stdout but emit From <url> / <ref> -> <ref> lines on stderr.
Sourcepub fn remote_list(&self) -> Result<RemoteListOutput>
pub fn remote_list(&self) -> Result<RemoteListOutput>
Enumerate remotes with their fetch / push URLs.
We use git remote -v rather than git2’s Repository::remotes so the
output matches what git itself reports (and naturally handles the
case where fetch and push URLs diverge via pushurl).
Sourcepub fn branch_status(
&self,
branch: &str,
base: &str,
) -> Result<BranchStatusOutput>
pub fn branch_status( &self, branch: &str, base: &str, ) -> Result<BranchStatusOutput>
Compare branch against base and report ahead / behind counts plus
the merge-base, using git2’s graph_ahead_behind for the count and a
git merge-base shell-out for the common-ancestor sha (git2’s
merge_base returns an OID but we want the textual form).
Sourcepub fn unpushed_commits(
&self,
branch: &str,
remote: &str,
) -> Result<UnpushedCommitsOutput>
pub fn unpushed_commits( &self, branch: &str, remote: &str, ) -> Result<UnpushedCommitsOutput>
List commits that exist on branch but not on <remote>/<branch>.
Sourcepub fn is_pushed(&self, commit: &str, remote: &str) -> Result<IsPushedOutput>
pub fn is_pushed(&self, commit: &str, remote: &str) -> Result<IsPushedOutput>
Check whether commit is reachable from any remote-tracking ref
under refs/remotes/<remote>/.
Sourcepub fn tag_pushed(&self, tag: &str, remote: &str) -> Result<TagPushedOutput>
pub fn tag_pushed(&self, tag: &str, remote: &str) -> Result<TagPushedOutput>
Check whether tag exists on remote (via git ls-remote --tags).
Sourcepub fn worktree_state(
&self,
branch: Option<&str>,
) -> Result<WorktreeStateOutput>
pub fn worktree_state( &self, branch: Option<&str>, ) -> Result<WorktreeStateOutput>
Snapshot a worktree’s state (branch, tracking, ahead/behind, uncommitted).
Source§impl GitModule
impl GitModule
Sourcepub fn reset(
&self,
working_dir: &Path,
mode: ResetMode,
target: &str,
) -> Result<ResetOutput>
pub fn reset( &self, working_dir: &Path, mode: ResetMode, target: &str, ) -> Result<ResetOutput>
Move HEAD to target, with mode controlling the working tree
behaviour. The working directory MUST be owned by the current
session — see GitModule::ensure_session_scope.
ResetMode::Soft— move HEAD only (git reset --soft)ResetMode::Mixed— also reset index but keep worktree (--mixed)ResetMode::Hard— also overwrite worktree (--hard)
Source§impl GitModule
impl GitModule
Sourcepub fn session_release(&mut self) -> Result<SessionReleaseOutput>
pub fn session_release(&mut self) -> Result<SessionReleaseOutput>
Adopt orphan worktrees under .worktrees/ (those known to git worktree list but not yet owned by this session). Any branches
currently checked out inside them are adopted at the same time so
the normal branch_delete ownership check will pass.
Returns the set of worktrees / branches that were newly adopted. Already-owned entries are skipped silently — calling this repeatedly is idempotent.
Source§impl GitModule
impl GitModule
Sourcepub fn worktree_add(
&mut self,
name: &str,
branch: &str,
base_branch: Option<&str>,
) -> Result<WorktreeAddOutput>
pub fn worktree_add( &mut self, name: &str, branch: &str, base_branch: Option<&str>, ) -> Result<WorktreeAddOutput>
Create a new worktree under .worktrees/<name> on a new branch.
Sourcepub fn worktree_remove(&mut self, name: &str) -> Result<WorktreeRemoveOutput>
pub fn worktree_remove(&mut self, name: &str) -> Result<WorktreeRemoveOutput>
Remove a session-owned worktree (force-removed, then forgotten).
Sourcepub fn commit(
&self,
working_dir: &Path,
message: &str,
paths: Option<&[String]>,
) -> Result<CommitOutput>
pub fn commit( &self, working_dir: &Path, message: &str, paths: Option<&[String]>, ) -> Result<CommitOutput>
Stage and commit changes in working_dir.
When paths is None or empty, all changes (git add -A) are
staged; otherwise only the listed paths are.
Sourcepub fn merge(
&self,
branch: &str,
into_branch: &str,
working_dir: &Path,
) -> Result<MergeOutput>
pub fn merge( &self, branch: &str, into_branch: &str, working_dir: &Path, ) -> Result<MergeOutput>
Merge branch into into_branch via --no-ff. On failure, the
merge is auto-aborted and the original error surfaces.
Sourcepub fn branch_delete(&self, branch: &str) -> Result<BranchDeleteOutput>
pub fn branch_delete(&self, branch: &str) -> Result<BranchDeleteOutput>
Delete a session-owned branch (refuses to delete unmerged work; use
git branch -D directly if you really need that).