#[non_exhaustive]pub enum TransactionError {
Prepare {
operation: Option<usize>,
source: ReferenceError,
},
Publish {
outcomes: Vec<RefEditOutcome>,
source: ReferenceError,
},
}Expand description
Failure before publication or a report of effects already made.
Self::Prepare leaves ref and log contents unchanged. Self::Publish retains exact
outcomes without rollback; a reference may have advanced while its reflog append failed.
Retain the outcomes in diagnostics and read fresh state before designing a retry. Replaying
the same batch blindly can overwrite intervening work or duplicate log entries.
use girt::refs::{
Expected, RefEdit, RefName, RefOutcome, ReferenceError, Reflog, Target, TransactionError,
};
use girt::{InitKind, ObjectFormat, Repository};
let directory = tempfile::tempdir()?;
let repo = Repository::init(
ObjectFormat::Sha1,
directory.path().join("r.git"),
InitKind::Bare,
)?;
let refs = repo.references()?;
let name = RefName::new("refs/tags/result")?;
let id = repo.loose_objects().write_blob(b"build result")?;
let edit = RefEdit::new(
name.clone(),
Some(Target::Direct(id)),
Expected::Absent,
Reflog::Preserve,
);
let outcomes = refs.transaction(&[edit.clone()])?;
assert_eq!(outcomes[0].reference, RefOutcome::Published);
assert!(outcomes[0].logs.is_empty());
// A stale creation is refused before publication; don't replace it with Expected::Any.
assert!(matches!(
refs.transaction(&[edit]),
Err(TransactionError::Prepare {
operation: Some(0),
source: ReferenceError::Mismatch { .. },
})
));
assert_eq!(refs.read(&name)?, Some(Target::Direct(id)));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Prepare
No reference or log contents were changed. Empty directories can remain.
Fields
operation: Option<usize>Input index when the failure belongs to one operation; otherwise a batch/lock failure.
source: ReferenceErrorValidation, precondition, lock, or read failure.
Publish
Publication stopped at the first error, without rollback.
Fields
outcomes: Vec<RefEditOutcome>Exact completed effects in caller order; later operations can have packed removals.
source: ReferenceErrorUnderlying error. A loose unlink after packed removal retains PackedDeleted.
Trait Implementations§
Source§impl Debug for TransactionError
impl Debug for TransactionError
Source§impl Display for TransactionError
impl Display for TransactionError
Source§impl Error for TransactionError
impl Error for TransactionError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()