Skip to content

Commit

Permalink
feat: add Object::peel_to_commit() to assure an object turns into a…
Browse files Browse the repository at this point in the history
… commit.
  • Loading branch information
Byron committed Nov 5, 2024
1 parent 9e106c4 commit 2fce14f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion gix/src/object/peel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
object,
object::{peel, Kind},
Object, Tree,
Commit, Object, Tree,
};

///
Expand Down Expand Up @@ -69,10 +69,19 @@ impl<'repo> Object<'repo> {
}

/// Peel this object into a tree and return it, if this is possible.
///
/// This will follow tag objects and commits until their tree is reached.
pub fn peel_to_tree(self) -> Result<Tree<'repo>, peel::to_kind::Error> {
Ok(self.peel_to_kind(gix_object::Kind::Tree)?.into_tree())
}

/// Peel this object into a commit and return it, if this is possible.
///
/// This will follow tag objects until a commit is reached.
pub fn peel_to_commit(self) -> Result<Commit<'repo>, peel::to_kind::Error> {
Ok(self.peel_to_kind(gix_object::Kind::Commit)?.into_commit())
}

// TODO: tests
/// Follow all tag object targets until a commit, tree or blob is reached.
///
Expand Down

0 comments on commit 2fce14f

Please sign in to comment.