Skip to content

Commit 9de6a79

Browse files
committed
feat: shallow support for fetch operations.
TBD: more elaborate docs
1 parent 99def88 commit 9de6a79

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

gix/tests/remote/fetch.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,32 @@ mod blocking_and_async_io {
4343
#[allow(clippy::result_large_err)]
4444
pub(crate) fn try_repo_rw(
4545
name: &str,
46+
) -> Result<(gix::Repository, gix_testtools::tempfile::TempDir), gix::open::Error> {
47+
try_repo_rw_args(name, Vec::<String>::new(), Mode::FastClone)
48+
}
49+
50+
pub(crate) enum Mode {
51+
FastClone,
52+
CloneWithShallowSupport,
53+
}
54+
55+
#[allow(clippy::result_large_err)]
56+
pub(crate) fn try_repo_rw_args<S: Into<String>>(
57+
name: &str,
58+
args: impl IntoIterator<Item = S>,
59+
mode: Mode,
4660
) -> Result<(gix::Repository, gix_testtools::tempfile::TempDir), gix::open::Error> {
4761
let dir = gix_testtools::scripted_fixture_writable_with_args(
4862
"make_fetch_repos.sh",
49-
[base_repo_path()],
63+
[{
64+
let mut url = base_repo_path();
65+
if matches!(mode, Mode::CloneWithShallowSupport) {
66+
url.insert_str(0, "file://");
67+
}
68+
url
69+
}]
70+
.into_iter()
71+
.chain(args.into_iter().map(Into::into)),
5072
gix_testtools::Creation::ExecuteScript,
5173
)
5274
.unwrap();
@@ -84,6 +106,55 @@ mod blocking_and_async_io {
84106
Ok(())
85107
}
86108

109+
#[maybe_async::test(
110+
feature = "blocking-network-client",
111+
async(feature = "async-network-client-async-std", async_std::test)
112+
)]
113+
#[ignore]
114+
async fn fetch_shallow() -> crate::Result {
115+
let (repo, _tmp) = try_repo_rw_args("two-origins", ["--depth=2"], Mode::CloneWithShallowSupport)?;
116+
let remote = repo
117+
.head()?
118+
.into_remote(Fetch)
119+
.expect("present")?
120+
.with_fetch_tags(fetch::Tags::Included);
121+
122+
assert_eq!(
123+
repo.shallow_commits()?.expect("shallow clone").as_slice(),
124+
[
125+
hex_to_id("2d9d136fb0765f2e24c44a0f91984318d580d03b"),
126+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552"),
127+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552")
128+
]
129+
);
130+
let prev_commits = repo.head_id()?.ancestors().all()?.count();
131+
let changes = remote
132+
.connect(Fetch, gix::progress::Discard)
133+
.await?
134+
.prepare_fetch(Default::default())
135+
.await?
136+
.with_shallow(fetch::Shallow::Deepen(1))
137+
.receive(&AtomicBool::default())
138+
.await?;
139+
dbg!(changes);
140+
141+
assert_eq!(
142+
repo.shallow_commits()?.expect("shallow clone").as_slice(),
143+
[
144+
hex_to_id("2d9d136fb0765f2e24c44a0f91984318d580d03b"),
145+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552"),
146+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552")
147+
],
148+
"the shallow boundary was moved by one"
149+
);
150+
assert_ne!(
151+
repo.head_id()?.ancestors().all()?.count(),
152+
prev_commits,
153+
"more commits are available now"
154+
);
155+
Ok(())
156+
}
157+
87158
#[maybe_async::test(
88159
feature = "blocking-network-client",
89160
async(feature = "async-network-client-async-std", async_std::test)

0 commit comments

Comments
 (0)