Skip to content

Commit 6693ab9

Browse files
committed
feat(gix): support diff.ignoreSubmodules overrides in status
1 parent 04a18f3 commit 6693ab9

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

gix/src/status/index_worktree.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ mod submodule_status {
208208

209209
use crate::{
210210
bstr,
211-
bstr::BStr,
211+
bstr::{BStr, BString},
212212
status::{index_worktree::BuiltinSubmoduleStatus, Submodule},
213213
};
214214

@@ -247,6 +247,8 @@ mod submodule_status {
247247
SubmoduleStatus(#[from] crate::submodule::status::Error),
248248
#[error(transparent)]
249249
IgnoreConfig(#[from] crate::submodule::config::Error),
250+
#[error("The value of 'diff.submoduleIgnore' was invalid: '{actual}'")]
251+
DiffSubmoduleIgnoreConfig { actual: BString },
250252
}
251253

252254
impl gix_status::index_as_worktree::traits::SubmoduleStatus for BuiltinSubmoduleStatus {
@@ -275,7 +277,23 @@ mod submodule_status {
275277
return Ok(None);
276278
};
277279
let (ignore, check_dirty) = match self.mode {
278-
Submodule::AsConfigured { check_dirty } => (sm.ignore()?.unwrap_or_default(), check_dirty),
280+
Submodule::AsConfigured { check_dirty } => {
281+
// diff.ignoreSubmodules is the global setting, and if it exists, it overrides the submodule's own ignore setting.
282+
let global_ignore = repo.config_snapshot().string("diff.ignoreSubmodules");
283+
if let Some(ignore_str) = global_ignore {
284+
let ignore = ignore_str
285+
.as_ref()
286+
.try_into()
287+
.map_err(|_| Error::DiffSubmoduleIgnoreConfig {
288+
actual: ignore_str.into_owned(),
289+
})?;
290+
(ignore, check_dirty)
291+
} else {
292+
// If no global ignore is set, use the submodule's ignore setting.
293+
let ignore = sm.ignore()?.unwrap_or_default();
294+
(ignore, check_dirty)
295+
}
296+
}
279297
Submodule::Given { ignore, check_dirty } => (ignore, check_dirty),
280298
};
281299
let status = sm.status(ignore, check_dirty)?;

gix/src/status/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ where
2020
/// How to obtain a submodule's status.
2121
#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
2222
pub enum Submodule {
23-
/// Use the ['ignore' value](crate::Submodule::ignore) to determine which submodules
24-
/// participate in the status query, and to which extent.
23+
/// Use the `diff.submoduleIgnore` configuration to determine, or if not set,
24+
/// use the submodule's own ['ignore' value](crate::Submodule::ignore) to determine
25+
/// which submodules participate in the status query, and to which extent.
2526
AsConfigured {
2627
/// If `true`, default `false`, the computation will stop once the first in a ladder operations
2728
/// ordered from cheap to expensive shows that the submodule is dirty.

0 commit comments

Comments
 (0)