Skip to content

Commit b35e544

Browse files
committed
Add example that tries to trip someone who reads something from the index
This doesn't happen here though, so nothing special we could trigger.
1 parent 8896956 commit b35e544

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

gix-submodule/tests/file/baseline.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ fn common_values_and_names_by_path() -> crate::Result {
1414
assert_eq!(
1515
modules
1616
.iter()
17-
.map(|m| m.config_path().expect("present").to_owned())
17+
.map(|m| { m.config_path().expect("present").to_owned() })
1818
.collect::<Vec<_>>(),
1919
[
2020
"empty-clone/.gitmodules",
2121
"multiple/.gitmodules",
22+
"not-a-submodule/.gitmodules",
2223
"recursive-clone/.gitmodules",
2324
"recursive-clone/submodule/.gitmodules",
2425
"relative-clone/.gitmodules",

gix-submodule/tests/file/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ fn submodule(bytes: &str) -> gix_submodule::File {
55
mod is_active_platform {
66
use std::str::FromStr;
77

8-
use bstr::{BStr, ByteSlice};
9-
10-
fn multi_modules() -> crate::Result<gix_submodule::File> {
8+
fn module_file(name: &str) -> crate::Result<gix_submodule::File> {
119
let modules = gix_testtools::scripted_fixture_read_only("basic.sh")?
12-
.join("multiple")
10+
.join(name)
1311
.join(".gitmodules");
1412
Ok(gix_submodule::File::from_bytes(
1513
std::fs::read(&modules)?.as_slice(),
@@ -18,6 +16,12 @@ mod is_active_platform {
1816
)?)
1917
}
2018

19+
use bstr::{BStr, ByteSlice};
20+
21+
fn multi_modules() -> crate::Result<gix_submodule::File> {
22+
module_file("multiple")
23+
}
24+
2125
fn assume_valid_active_state<'a>(
2226
module: &'a gix_submodule::File,
2327
config: &'a gix_config::File<'static>,
@@ -52,6 +56,17 @@ mod is_active_platform {
5256
.collect())
5357
}
5458

59+
#[test]
60+
fn without_submodule_in_index() -> crate::Result {
61+
let module = module_file("not-a-submodule")?;
62+
assert_eq!(
63+
module.names().map(ToOwned::to_owned).collect::<Vec<_>>(),
64+
["submodule"],
65+
"entries can be read"
66+
);
67+
Ok(())
68+
}
69+
5570
#[test]
5671
fn without_any_additional_settings_all_are_inactive_if_they_have_a_url() -> crate::Result {
5772
let module = multi_modules()?;

gix-submodule/tests/fixtures/basic.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ git clone super recursive-clone
3737
(cd recursive-clone
3838
git submodule update --init --recursive
3939
)
40+
41+
git clone super not-a-submodule
42+
(cd not-a-submodule
43+
cp .gitmodules modules.bak
44+
git rm submodule
45+
echo fake > submodule
46+
mv modules.bak .gitmodules
47+
git add submodule && git commit -m "no submodule in index and commit, but in configuration"
48+
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:c961fe67eb7af352064aeae412cabf8b8260782db003ddea7ca251c491c4963e
3-
size 31404
2+
oid sha256:f1213af1023577c8c59e1a065530785e28ee10e4e04f731597aebc6a63e3dc86
3+
size 32472

0 commit comments

Comments
 (0)