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
impl GitExecutor
Sourcepub fn has_changes() -> Result<bool, GitExecutorError>
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).
Sourcepub fn stage_files(files: &[String]) -> Result<(), GitExecutorError>
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.
Sourcepub fn commit(message: &str, amend: bool) -> Result<String, GitExecutorError>
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.
Sourcepub fn push(branch: Option<&str>) -> Result<(), GitExecutorError>
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).
Sourcepub fn current_branch() -> Result<String, GitExecutorError>
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.
Sourcepub fn get_head_sha() -> Result<String, GitExecutorError>
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.
Sourcepub fn auto_commit_with_files(
config: &AutoCommitConfig,
session_files: Option<&[String]>,
tool_name: Option<&str>,
session_id: Option<&str>,
) -> AutoCommitResult
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.
Sourcepub fn auto_commit(config: &AutoCommitConfig) -> AutoCommitResult
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.