Skip to content

Commit 2fce14f

Browse files
committed
feat: add Object::peel_to_commit() to assure an object turns into a commit.
1 parent 9e106c4 commit 2fce14f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

gix/src/object/peel.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
object,
55
object::{peel, Kind},
6-
Object, Tree,
6+
Commit, Object, Tree,
77
};
88

99
///
@@ -69,10 +69,19 @@ impl<'repo> Object<'repo> {
6969
}
7070

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

78+
/// Peel this object into a commit and return it, if this is possible.
79+
///
80+
/// This will follow tag objects until a commit is reached.
81+
pub fn peel_to_commit(self) -> Result<Commit<'repo>, peel::to_kind::Error> {
82+
Ok(self.peel_to_kind(gix_object::Kind::Commit)?.into_commit())
83+
}
84+
7685
// TODO: tests
7786
/// Follow all tag object targets until a commit, tree or blob is reached.
7887
///

0 commit comments

Comments
 (0)