Skip to content

Commit 0871a96

Browse files
committed
feat: Object::peel_to_tree() as convenience method. (#470)
It's very common to try to work with trees, so let's make that easier.
1 parent 0ac4a2c commit 0871a96

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

git-repository/src/object/peel.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use crate::{
33
object,
44
object::{peel, Kind},
5-
Object,
5+
Object, Tree,
66
};
77

88
///
@@ -67,6 +67,11 @@ impl<'repo> Object<'repo> {
6767
}
6868
}
6969

70+
/// Peel this object into a tree and return it, if this is possible.
71+
pub fn peel_to_tree(self) -> Result<Tree<'repo>, peel::to_kind::Error> {
72+
Ok(self.peel_to_kind(git_object::Kind::Tree)?.into_tree())
73+
}
74+
7075
// TODO: tests
7176
/// Follow all tag object targets until a commit, tree or blob is reached.
7277
///

0 commit comments

Comments
 (0)