Skip to content

Commit 93d412c

Browse files
committed
feat: shallow support for fetch operations.
TBD: more elaborate docs
1 parent 4e89c19 commit 93d412c

File tree

1 file changed

+76
-1
lines changed

1 file changed

+76
-1
lines changed

gix/tests/remote/fetch.rs

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod shallow {
1414
mod blocking_and_async_io {
1515
use std::sync::atomic::AtomicBool;
1616

17+
use gix::remote::fetch::Status;
1718
use gix::remote::{fetch, Direction::Fetch};
1819
use gix_features::progress;
1920
use gix_protocol::maybe_async;
@@ -43,10 +44,32 @@ mod blocking_and_async_io {
4344
#[allow(clippy::result_large_err)]
4445
pub(crate) fn try_repo_rw(
4546
name: &str,
47+
) -> Result<(gix::Repository, gix_testtools::tempfile::TempDir), gix::open::Error> {
48+
try_repo_rw_args(name, Vec::<String>::new(), Mode::FastClone)
49+
}
50+
51+
pub(crate) enum Mode {
52+
FastClone,
53+
CloneWithShallowSupport,
54+
}
55+
56+
#[allow(clippy::result_large_err)]
57+
pub(crate) fn try_repo_rw_args<S: Into<String>>(
58+
name: &str,
59+
args: impl IntoIterator<Item = S>,
60+
mode: Mode,
4661
) -> Result<(gix::Repository, gix_testtools::tempfile::TempDir), gix::open::Error> {
4762
let dir = gix_testtools::scripted_fixture_writable_with_args(
4863
"make_fetch_repos.sh",
49-
[base_repo_path()],
64+
[{
65+
let mut url = base_repo_path();
66+
if matches!(mode, Mode::CloneWithShallowSupport) {
67+
url.insert_str(0, "file://");
68+
}
69+
url
70+
}]
71+
.into_iter()
72+
.chain(args.into_iter().map(Into::into)),
5073
gix_testtools::Creation::ExecuteScript,
5174
)
5275
.unwrap();
@@ -84,6 +107,58 @@ mod blocking_and_async_io {
84107
Ok(())
85108
}
86109

110+
#[maybe_async::test(
111+
feature = "blocking-network-client",
112+
async(feature = "async-network-client-async-std", async_std::test)
113+
)]
114+
async fn fetch_shallow_deepen_not_possible() -> 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+
140+
assert!(
141+
matches!(changes.status, Status::Change {write_pack_bundle, ..} if write_pack_bundle.index.num_objects == 0),
142+
"we get an empty pack as there is nothing to do"
143+
);
144+
145+
assert_eq!(
146+
repo.shallow_commits()?.expect("shallow clone").as_slice(),
147+
[
148+
hex_to_id("2d9d136fb0765f2e24c44a0f91984318d580d03b"),
149+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552"),
150+
hex_to_id("dfd0954dabef3b64f458321ef15571cc1a46d552")
151+
],
152+
"the base is shallow, and so is the clone, and we can't extend further"
153+
);
154+
assert_eq!(
155+
repo.head_id()?.ancestors().all()?.count(),
156+
prev_commits,
157+
"no more commits are available - there simply isn't more information"
158+
);
159+
Ok(())
160+
}
161+
87162
#[maybe_async::test(
88163
feature = "blocking-network-client",
89164
async(feature = "async-network-client-async-std", async_std::test)

0 commit comments

Comments
 (0)