pub enum Head {
Branch {
name: String,
oid: Oid,
},
Detached {
oid: Oid,
},
}Expand description
Represents the current HEAD state of a Git repository.
HEAD can either point to a branch (normal state) or directly to a commit (detached HEAD state).
Variants§
Branch
HEAD points to a branch (e.g., refs/heads/main).
Fields
Detached
HEAD points directly to a commit (detached state).
Implementations§
Source§impl Head
impl Head
Sourcepub fn branch(name: impl Into<String>, oid: Oid) -> Self
pub fn branch(name: impl Into<String>, oid: Oid) -> Self
Creates a new Head pointing to a branch.
§Arguments
name- The branch name (withoutrefs/heads/prefix).oid- The commit OID the branch points to.
Sourcepub fn oid(&self) -> &Oid
pub fn oid(&self) -> &Oid
Returns the commit OID that HEAD points to.
This works for both branch and detached states.
Sourcepub fn branch_name(&self) -> Option<&str>
pub fn branch_name(&self) -> Option<&str>
Returns the branch name if HEAD points to a branch.
Returns None if HEAD is in detached state.
Sourcepub fn is_detached(&self) -> bool
pub fn is_detached(&self) -> bool
Returns true if HEAD is in detached state.
Sourcepub fn reference_name(&self) -> String
pub fn reference_name(&self) -> String
Returns the full reference name.
For branches, returns refs/heads/<name>.
For detached HEAD, returns the commit OID as hex.
Trait Implementations§
impl Eq for Head
impl StructuralPartialEq for Head
Auto Trait Implementations§
impl Freeze for Head
impl RefUnwindSafe for Head
impl Send for Head
impl Sync for Head
impl Unpin for Head
impl UnwindSafe for Head
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more