mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
feat(git_metrics): add option to ignore submodules (#5052)
* add docs * update schema * ok, actually update schema * add test * fix lint * accidentally included my .devenv directory
This commit is contained in:
parent
27ffa37cfd
commit
ce01423152
5
.github/config-schema.json
vendored
5
.github/config-schema.json
vendored
@ -576,6 +576,7 @@
|
|||||||
"deleted_style": "bold red",
|
"deleted_style": "bold red",
|
||||||
"disabled": true,
|
"disabled": true,
|
||||||
"format": "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
"format": "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
||||||
|
"ignore_submodules": false,
|
||||||
"only_nonzero_diffs": true
|
"only_nonzero_diffs": true
|
||||||
},
|
},
|
||||||
"allOf": [
|
"allOf": [
|
||||||
@ -3188,6 +3189,10 @@
|
|||||||
"disabled": {
|
"disabled": {
|
||||||
"default": true,
|
"default": true,
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"ignore_submodules": {
|
||||||
|
"default": false,
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
@ -1820,6 +1820,7 @@ To enable it, set `disabled` to `false` in your configuration file.
|
|||||||
| `only_nonzero_diffs` | `true` | Render status only for changed items. |
|
| `only_nonzero_diffs` | `true` | Render status only for changed items. |
|
||||||
| `format` | `'([+$added]($added_style) )([-$deleted]($deleted_style) )'` | The format for the module. |
|
| `format` | `'([+$added]($added_style) )([-$deleted]($deleted_style) )'` | The format for the module. |
|
||||||
| `disabled` | `true` | Disables the `git_metrics` module. |
|
| `disabled` | `true` | Disables the `git_metrics` module. |
|
||||||
|
| `ignore_submodules` | `false` | Ignore changes to submodules |
|
||||||
|
|
||||||
### Variables
|
### Variables
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ pub struct GitMetricsConfig<'a> {
|
|||||||
pub only_nonzero_diffs: bool,
|
pub only_nonzero_diffs: bool,
|
||||||
pub format: &'a str,
|
pub format: &'a str,
|
||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
|
pub ignore_submodules: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for GitMetricsConfig<'a> {
|
impl<'a> Default for GitMetricsConfig<'a> {
|
||||||
@ -23,6 +24,7 @@ impl<'a> Default for GitMetricsConfig<'a> {
|
|||||||
only_nonzero_diffs: true,
|
only_nonzero_diffs: true,
|
||||||
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
format: "([+$added]($added_style) )([-$deleted]($deleted_style) )",
|
||||||
disabled: true,
|
disabled: true,
|
||||||
|
ignore_submodules: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,20 +23,21 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
|||||||
let repo = context.get_repo().ok()?;
|
let repo = context.get_repo().ok()?;
|
||||||
let repo_root = repo.workdir.as_ref()?;
|
let repo_root = repo.workdir.as_ref()?;
|
||||||
|
|
||||||
let diff = context
|
let mut args = vec![
|
||||||
.exec_cmd(
|
OsStr::new("--git-dir"),
|
||||||
"git",
|
repo.path.as_os_str(),
|
||||||
&[
|
OsStr::new("--work-tree"),
|
||||||
OsStr::new("--git-dir"),
|
repo_root.as_os_str(),
|
||||||
repo.path.as_os_str(),
|
OsStr::new("--no-optional-locks"),
|
||||||
OsStr::new("--work-tree"),
|
OsStr::new("diff"),
|
||||||
repo_root.as_os_str(),
|
OsStr::new("--shortstat"),
|
||||||
OsStr::new("--no-optional-locks"),
|
];
|
||||||
OsStr::new("diff"),
|
|
||||||
OsStr::new("--shortstat"),
|
if config.ignore_submodules {
|
||||||
],
|
args.push(OsStr::new("--ignore-submodules"));
|
||||||
)?
|
}
|
||||||
.stdout;
|
|
||||||
|
let diff = context.exec_cmd("git", &args)?.stdout;
|
||||||
|
|
||||||
let stats = GitDiff::parse(&diff);
|
let stats = GitDiff::parse(&diff);
|
||||||
|
|
||||||
@ -228,6 +229,33 @@ mod tests {
|
|||||||
repo_dir.close()
|
repo_dir.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shows_all_changes_with_ignored_submodules() -> io::Result<()> {
|
||||||
|
let repo_dir = create_repo_with_commit()?;
|
||||||
|
let path = repo_dir.path();
|
||||||
|
|
||||||
|
let file_path = path.join("the_file");
|
||||||
|
write_file(file_path, "\nSecond Line\n\nModified\nAdded\n")?;
|
||||||
|
|
||||||
|
let actual = ModuleRenderer::new("git_metrics")
|
||||||
|
.config(toml::toml! {
|
||||||
|
[git_metrics]
|
||||||
|
disabled = false
|
||||||
|
ignore_submodules = true
|
||||||
|
})
|
||||||
|
.path(path)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let expected = Some(format!(
|
||||||
|
"{} {} ",
|
||||||
|
Color::Green.bold().paint("+4"),
|
||||||
|
Color::Red.bold().paint("-2")
|
||||||
|
));
|
||||||
|
|
||||||
|
assert_eq!(expected, actual);
|
||||||
|
repo_dir.close()
|
||||||
|
}
|
||||||
|
|
||||||
fn render_metrics(path: &Path) -> Option<String> {
|
fn render_metrics(path: &Path) -> Option<String> {
|
||||||
ModuleRenderer::new("git_metrics")
|
ModuleRenderer::new("git_metrics")
|
||||||
.config(toml::toml! {
|
.config(toml::toml! {
|
||||||
|
Loading…
Reference in New Issue
Block a user