Skip to content

Commit 25c5bce

Browse files
committed
fix!: IsActivePlatform::is_active() now only considers the URL in passed configuration
Previously, it would consider the presence of `url` in the `.gitmodules` file as well, which is not the way git does it.
1 parent 4ef9a32 commit 25c5bce

File tree

3 files changed

+19
-40
lines changed

3 files changed

+19
-40
lines changed

gix-submodule/src/access.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ impl File {
5656
) -> bool
5757
+ 'a,
5858
) -> Result<
59-
impl Iterator<Item = (&BStr, Result<bool, crate::is_active_platform::is_active::Error>)> + 'a,
59+
impl Iterator<Item = (&BStr, Result<bool, gix_config::value::Error>)> + 'a,
6060
crate::is_active_platform::Error,
6161
> {
6262
let mut platform = self.is_active_platform(config, defaults)?;
6363
let iter = self
6464
.names()
65-
.map(move |name| (name, platform.is_active(self, config, name, &mut attributes)));
65+
.map(move |name| (name, platform.is_active(config, name, &mut attributes)));
6666
Ok(iter)
6767
}
6868

gix-submodule/src/is_active_platform.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,19 @@ pub enum Error {
1212
ParsePattern(#[from] gix_pathspec::parse::Error),
1313
}
1414

15-
///
16-
pub mod is_active {
17-
/// The error returned by the iterator of [File::names_and_active_state](crate::File::names_and_active_state()).
18-
#[derive(Debug, thiserror::Error)]
19-
#[allow(missing_docs)]
20-
pub enum Error {
21-
#[error("The value of the 'active' field of a submodule could not be decoded")]
22-
ActiveField(#[from] gix_config::value::Error),
23-
#[error(transparent)]
24-
Url(#[from] crate::config::url::Error),
25-
}
26-
}
27-
2815
impl IsActivePlatform {
2916
/// Returns `true` if the submodule named `name` is active or `false` otherwise.
30-
/// `modules` is the instance that [is_active_platform()](crate::File::is_active_platform()) was called on, and
31-
/// `config` is the configuration that was passed there as well.
32-
/// `attributes(relative_path, case, is_dir, outcome)` provides a way to resolve the attributes mentioned in `submodule.active` pathspecs
33-
/// that are evaluated in the platforms git configuration.
17+
/// `config` is the configuration that was passed to the originating [modules file](crate::File).
18+
/// `attributes(relative_path, case, is_dir, outcome)` provides a way to resolve the attributes mentioned
19+
/// in `submodule.active` pathspecs that are evaluated in the platforms git configuration.
3420
///
3521
/// A submodule's active state is determined in the following order
3622
///
37-
/// * it's `submodule.<name>.active` configuration is set
23+
/// * it's `submodule.<name>.active` is set in `config`
3824
/// * it matches a `submodule.active` pathspec either positively or negatively via `:!<spec>`
39-
/// * it's active if it has a `url`
25+
/// * it's active if it has any `url` set in `config`
4026
pub fn is_active(
4127
&mut self,
42-
modules: &crate::File,
4328
config: &gix_config::File<'static>,
4429
name: &BStr,
4530
attributes: impl FnMut(
@@ -48,7 +33,7 @@ impl IsActivePlatform {
4833
bool,
4934
&mut gix_pathspec::attributes::search::Outcome,
5035
) -> bool,
51-
) -> Result<bool, is_active::Error> {
36+
) -> Result<bool, gix_config::value::Error> {
5237
if let Some(val) = config.boolean("submodule", Some(name), "active").transpose()? {
5338
return Ok(val);
5439
};
@@ -59,10 +44,6 @@ impl IsActivePlatform {
5944
}) {
6045
return Ok(val);
6146
}
62-
Ok(match modules.url(name) {
63-
Ok(_) => true,
64-
Err(crate::config::url::Error::Missing { .. }) => false,
65-
Err(err) => return Err(err.into()),
66-
})
47+
Ok(config.string("submodule", Some(name), "url").is_some())
6748
}
6849
}

gix-submodule/tests/file/mod.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,23 @@ mod is_active_platform {
4646
.map(|name| {
4747
(
4848
name.to_str().expect("valid"),
49-
platform
50-
.is_active(module, config, name, &mut attributes)
51-
.expect("valid"),
49+
platform.is_active(config, name, &mut attributes).expect("valid"),
5250
)
5351
})
5452
.collect())
5553
}
5654

5755
#[test]
58-
fn without_any_additional_settings_all_are_active_if_they_have_a_url() -> crate::Result {
56+
fn without_any_additional_settings_all_are_inactive_if_they_have_a_url() -> crate::Result {
5957
let module = multi_modules()?;
6058
assert_eq!(
6159
assume_valid_active_state(&module, &Default::default(), Default::default())?,
6260
&[
63-
("submodule", true),
64-
("a/b", true),
65-
(".a/..c", true),
66-
("a/d\\", true),
67-
("a\\e", true)
61+
("submodule", false),
62+
("a/b", false),
63+
(".a/..c", false),
64+
("a/d\\", false),
65+
("a\\e", false)
6866
]
6967
);
7068
Ok(())
@@ -77,16 +75,16 @@ mod is_active_platform {
7775
assume_valid_active_state(
7876
&module,
7977
&gix_config::File::from_str(
80-
"[submodule.submodule]\n active = 0\n[submodule \"a/b\"]\n active = false"
78+
"[submodule.submodule]\n active = 0\n url = set \n[submodule \"a/b\"]\n active = false \n url = set \n[submodule \".a/..c\"] active = 1"
8179
)?,
8280
Default::default()
8381
)?,
8482
&[
8583
("submodule", false),
8684
("a/b", false),
8785
(".a/..c", true),
88-
("a/d\\", true),
89-
("a\\e", true)
86+
("a/d\\", false),
87+
("a\\e", false)
9088
]
9189
);
9290
Ok(())

0 commit comments

Comments
 (0)