Skip to main content

GitExecutor

Struct GitExecutor 

Source
pub struct GitExecutor;
Expand description

Executes git operations for auto-commit.

A zero-sized type whose methods each shell out to git and return the result. No state is held between calls, so every invocation starts a fresh subprocess; this keeps the executor trivially thread-safe at the cost of one git process per operation.

Implementations§

Source§

impl GitExecutor

Source

pub fn has_changes() -> Result<bool, GitExecutorError>

Check whether the working tree has uncommitted changes.

Runs git status --porcelain and returns true when any output is produced. Use this to short-circuit a commit attempt before staging, avoiding the overhead of a git commit invocation that would refuse to run anyway.

§Errors

Returns GitExecutorError::ExecutionFailed if git is not available, or GitExecutorError::GitError if the command fails (for example, outside a repository).

Source

pub fn stage_files(files: &[String]) -> Result<(), GitExecutorError>

Stage files for commit.

Each path in files is passed to git add -- <path> individually, scoping staging to exactly the listed paths. An empty slice is refused with an error rather than falling through to git add -A: the auto-commit hook is meant to commit only the agent’s own recorded modifications, so staging the entire working tree would silently sweep up unrelated edits and secret files (.env, credentials, scratch buffers). Misconfiguration must fail loudly, not broaden scope.

§Errors

Returns GitExecutorError::GitError if files is empty — populate AutoCommitConfig::files or record modifications through the hook. Returns GitExecutorError if any individual git add invocation fails; earlier files in the list may already be staged.

Source

pub fn commit(message: &str, amend: bool) -> Result<String, GitExecutorError>

Create a commit with the given message.

Runs git commit (optionally with --amend when amend is true) and returns the SHA of the resulting commit. The “nothing to commit” case is mapped to GitExecutorError::NoChanges so callers can distinguish it from a genuine failure without parsing git’s stderr.

§Errors

Returns GitExecutorError::NoChanges if there is nothing to commit, or any other GitExecutorError variant on failure.

Source

pub fn push(branch: Option<&str>) -> Result<(), GitExecutorError>

Push the current branch to the configured remote.

Resolves the branch from branch when given, otherwise from the currently checked-out branch via current_branch. The push targets origin and is non-forceful — it will fail if the remote has diverged.

§Errors

Returns GitExecutorError if branch resolution or the push itself fails (for example, no upstream configured or non-fast-forward).

Source

pub fn current_branch() -> Result<String, GitExecutorError>

Get the currently checked-out branch name.

Runs git rev-parse --abbrev-ref HEAD and trims whitespace. Returns "HEAD" when in a detached-HEAD state (git’s own convention).

§Errors

Returns GitExecutorError if git is unavailable or not inside a repository.

Source

pub fn get_head_sha() -> Result<String, GitExecutorError>

Get the full SHA of the current HEAD commit.

Runs git rev-parse HEAD and trims whitespace. Returns the full object name (40 characters for SHA-1) rather than the short form.

§Errors

Returns GitExecutorError if git is unavailable or not inside a repository.

Source

pub fn auto_commit_with_files( config: &AutoCommitConfig, session_files: Option<&[String]>, tool_name: Option<&str>, session_id: Option<&str>, ) -> AutoCommitResult

Perform auto-commit with the given configuration.

Checks for changes, stages files, creates a commit, and optionally pushes. Returns AutoCommitResult describing the outcome.

When session_files is Some, only those paths are staged and committed, preventing unrelated working-tree changes from leaking into the commit. The commit message is AutoCommitConfig::message_template with {{tool}} / {{session}} expanded from tool_name / session_id — an unsupplied value expands to an empty string, and any other braced text passes through verbatim.

Source

pub fn auto_commit(config: &AutoCommitConfig) -> AutoCommitResult

Perform auto-commit using the file list from the config.

Convenience wrapper around auto_commit_with_files that passes None for the session-files override and both template values, so AutoCommitConfig::files controls what gets staged and any {{tool}} / {{session}} placeholder expands to an empty string.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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