Skip to content

Commit fdc3678

Browse files
committed
[repository #190] test for oid.ancestors().all()
1 parent 6da3599 commit fdc3678

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

git-repository/src/easy/head.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ pub mod log {
7878
}
7979

8080
pub mod peel {
81-
use git_hash::ObjectId;
82-
8381
use crate::{
8482
easy,
8583
easy::{head::Kind, Access, Head},
@@ -136,23 +134,19 @@ pub mod peel {
136134
})
137135
}
138136

139-
pub fn into_fully_peeled_id(self) -> Option<Result<ObjectId, Error>> {
137+
pub fn into_fully_peeled_id(self) -> Option<Result<easy::Oid<'repo, A>, Error>> {
140138
Some(match self.kind {
141139
Kind::Unborn(_name) => return None,
142140
Kind::Detached {
143141
peeled: Some(peeled), ..
144-
} => Ok(peeled),
142+
} => Ok(peeled.attach(self.access)),
145143
Kind::Detached { peeled: None, target } => target
146144
.attach(self.access)
147145
.object()
148146
.map_err(Into::into)
149147
.and_then(|obj| obj.peel_to_end().map_err(Into::into))
150-
.map(|peeled| peeled.id),
151-
Kind::Symbolic(r) => r
152-
.attach(self.access)
153-
.peel_to_id_in_place()
154-
.map_err(Into::into)
155-
.map(|id| id.detach()),
148+
.map(|obj| obj.id.attach(self.access)),
149+
Kind::Symbolic(r) => r.attach(self.access).peel_to_id_in_place().map_err(Into::into),
156150
})
157151
}
158152
}

git-repository/src/easy/oid.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#![allow(missing_docs)]
2-
use std::ops::Deref;
2+
use std::{cell::RefMut, ops::Deref};
33

44
use git_hash::{oid, ObjectId};
55

66
use crate::{
77
easy,
88
easy::{ext::ObjectAccessExt, object::find, ObjectRef, Oid},
99
};
10-
use std::cell::RefMut;
1110

1211
impl<'repo, A> Oid<'repo, A>
1312
where
@@ -62,12 +61,15 @@ where
6261
}
6362

6463
pub mod ancestors {
65-
use crate::easy;
66-
use crate::easy::oid::Ancestors;
67-
use crate::easy::Oid;
68-
use git_odb::Find;
6964
use std::ops::{Deref, DerefMut};
7065

66+
use git_odb::Find;
67+
68+
use crate::{
69+
easy,
70+
easy::{oid::Ancestors, Oid},
71+
};
72+
7173
impl<'repo, A> Oid<'repo, A>
7274
where
7375
A: easy::Access + Sized,
@@ -96,7 +98,6 @@ pub mod ancestors {
9698
where
9799
A: easy::Access + Sized,
98100
{
99-
// TODO: tests
100101
pub fn all(&mut self) -> Iter<'_, 'repo, A> {
101102
Iter {
102103
access: self.access,
@@ -139,8 +140,9 @@ pub mod ancestors {
139140
BorrowBufMut(#[from] easy::borrow::state::Error),
140141
}
141142
}
142-
use crate::ext::ObjectIdExt;
143143
use error::Error;
144+
145+
use crate::ext::ObjectIdExt;
144146
}
145147

146148
mod impls {

git-repository/tests/easy/ext/object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ mod commit {
8787
"we get the actual HEAD log, not the log of some reference"
8888
);
8989
let current_commit = repo.head()?.into_fully_peeled_id().expect("born")?;
90-
assert_eq!(current_commit, &*first_commit_id, "the commit was set");
90+
assert_eq!(current_commit, first_commit_id, "the commit was set");
9191

9292
let second_commit_id = repo.commit(
9393
"refs/heads/new-branch",

git-repository/tests/easy/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod access;
22
mod ext;
33
mod object;
4+
mod oid;
45
mod reference;

git-repository/tests/easy/oid.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
mod ancestors {
2+
use git_repository::prelude::ReferenceAccessExt;
3+
4+
#[test]
5+
fn all() -> crate::Result {
6+
let repo = crate::basic_repo()?;
7+
assert_eq!(
8+
repo.head()?
9+
.into_fully_peeled_id()
10+
.expect("born")?
11+
.ancestors()?
12+
.all()
13+
.count(),
14+
2,
15+
"need a specific amount of commits"
16+
);
17+
Ok(())
18+
}
19+
}

0 commit comments

Comments
 (0)