History

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.

Sebastian Thiel committed 3 years ago

Commit 25c5bce1 parent 4ef9a323 files · +19 −40Browse files

Unified · Split

3 files
  1. gix-submodule/src/access.rs +2 −2
  2. gix-submodule/src/is_active_platform.rs +7 −26
  3. gix-submodule/tests/file/mod.rs +10 −12
gix-submodule/src/access.rs+2−2
@@ -56,13 +56,13 @@ impl File { · 55 unmodified lines
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+7−26
@@ -12,34 +12,19 @@ pub enum Error { · 11 unmodified lines
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 { · 2 unmodified lines
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 { · 4 unmodified lines
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+10−12
@@ -46,25 +46,23 @@ mod is_active_platform { · 45 unmodified lines
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,7 +75,7 @@ mod is_active_platform { · 6 unmodified lines
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 )?,
@@ -85,8 +83,8 @@ mod is_active_platform { · 1 unmodified line
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(())

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t