Skip to content

Commit 29f0760

Browse files
committed
place shallow git dependencies into a different directory.
That way, we avoid any danger with older cargo's not being able to handle such a repository correctly.
1 parent 1df5b3b commit 29f0760

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

src/cargo/sources/git/source.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ impl<'cfg> GitSource<'cfg> {
2929
assert!(source_id.is_git(), "id is not git, id={}", source_id);
3030

3131
let remote = GitRemote::new(source_id.url());
32-
let ident = ident(&source_id);
32+
let ident = ident_shallow(
33+
&source_id,
34+
config
35+
.cli_unstable()
36+
.gitoxide
37+
.map_or(false, |gix| gix.fetch && gix.shallow_deps),
38+
);
3339

3440
let source = GitSource {
3541
remote,
@@ -76,6 +82,14 @@ fn ident(id: &SourceId) -> String {
7682
format!("{}-{}", ident, short_hash(id.canonical_url()))
7783
}
7884

85+
fn ident_shallow(id: &SourceId, is_shallow: bool) -> String {
86+
let mut ident = ident(id);
87+
if is_shallow {
88+
ident.push_str("-shallow");
89+
}
90+
ident
91+
}
92+
7993
impl<'cfg> Debug for GitSource<'cfg> {
8094
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
8195
write!(f, "git repo at {}", self.remote.url())?;

tests/testsuite/git.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,15 +2092,20 @@ fn gitoxide_clones_git_dependency_with_shallow_protocol_and_follow_up_fetch_main
20922092
.masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
20932093
.run();
20942094

2095-
let db_clone = gix::open_opts(
2096-
glob::glob(paths::home().join(".cargo/git/db/bar-*").to_str().unwrap())?
2097-
.next()
2098-
.unwrap()?,
2095+
let shallow_db_clone = gix::open_opts(
2096+
glob::glob(
2097+
paths::home()
2098+
.join(".cargo/git/db/bar-*-shallow")
2099+
.to_str()
2100+
.unwrap(),
2101+
)?
2102+
.next()
2103+
.unwrap()?,
20992104
gix::open::Options::isolated(),
21002105
)?;
2101-
assert!(db_clone.is_shallow());
2106+
assert!(shallow_db_clone.is_shallow());
21022107
assert_eq!(
2103-
db_clone
2108+
shallow_db_clone
21042109
.rev_parse_single("origin/master")?
21052110
.ancestors()
21062111
.all()?
@@ -2145,16 +2150,24 @@ fn gitoxide_clones_git_dependency_with_shallow_protocol_and_follow_up_fetch_main
21452150
.masquerade_as_nightly_cargo(&["unstable features must be available for -Z gitoxide"])
21462151
.run();
21472152

2153+
let db_clone = gix::open_opts(
2154+
glob::glob(paths::home().join(".cargo/git/db/bar-*").to_str().unwrap())?
2155+
.map(Result::unwrap)
2156+
.filter(|p| !p.to_string_lossy().ends_with("-shallow"))
2157+
.next()
2158+
.unwrap(),
2159+
gix::open::Options::isolated(),
2160+
)?;
21482161
assert_eq!(
21492162
db_clone
21502163
.rev_parse_single("origin/master")?
21512164
.ancestors()
21522165
.all()?
21532166
.count(),
2154-
2,
2155-
"the new commit was fetched into our DB clone"
2167+
3,
2168+
"we created an entirely new non-shallow clone"
21562169
);
2157-
assert!(db_clone.is_shallow());
2170+
assert!(!db_clone.is_shallow());
21582171
assert_eq!(
21592172
dep_checkout.head_id()?.ancestors().all()?.count(),
21602173
1,
@@ -2168,8 +2181,14 @@ fn gitoxide_clones_git_dependency_with_shallow_protocol_and_follow_up_fetch_main
21682181
.unwrap(),
21692182
)?
21702183
.map(|path| -> anyhow::Result<usize> {
2171-
let dep_checkout = gix::open_opts(path?, gix::open::Options::isolated())?;
2172-
assert!(dep_checkout.is_shallow());
2184+
let path = path?;
2185+
let dep_checkout = gix::open_opts(&path, gix::open::Options::isolated())?;
2186+
dbg!(dep_checkout.git_dir());
2187+
assert_eq!(
2188+
dep_checkout.is_shallow(),
2189+
path.to_string_lossy().contains("-shallow"),
2190+
"checkouts of shallow db repos are shallow as well"
2191+
);
21732192
let depth = dep_checkout.head_id()?.ancestors().all()?.count();
21742193
Ok(depth)
21752194
})
@@ -2178,8 +2197,8 @@ fn gitoxide_clones_git_dependency_with_shallow_protocol_and_follow_up_fetch_main
21782197
.expect("two checkout repos");
21792198

21802199
assert_eq!(
2181-
max_history_depth, 2,
2182-
"the new checkout sees all commits of the DB"
2200+
max_history_depth, 3,
2201+
"we see the previous shallow checkout as well as new new unshallow one"
21832202
);
21842203

21852204
Ok(())

0 commit comments

Comments
 (0)