diff --git a/crates/nu_plugin_gstat/src/gstat.rs b/crates/nu_plugin_gstat/src/gstat.rs index 92c2bc45ed..496032a293 100644 --- a/crates/nu_plugin_gstat/src/gstat.rs +++ b/crates/nu_plugin_gstat/src/gstat.rs @@ -21,6 +21,7 @@ impl GStat { value: &Value, current_dir: &str, path: Option>, + calculate_tag: bool, span: Span, ) -> Result { // use std::any::Any; @@ -92,14 +93,14 @@ impl GStat { .map(|p| p.to_string_lossy().to_string()) .unwrap_or_else(|| "".to_string()); - let mut desc_opts = DescribeOptions::new(); - desc_opts.describe_tags(); - - let tag = if let Ok(Ok(s)) = repo.describe(&desc_opts).map(|d| d.format(None)) { - s - } else { - "no_tag".to_string() - }; + let tag = calculate_tag + .then(|| { + let mut desc_opts = DescribeOptions::new(); + desc_opts.describe_tags(); + repo.describe(&desc_opts).ok()?.format(None).ok() + }) + .flatten() + .unwrap_or_else(|| "no_tag".to_string()); // Leave this in case we want to turn it into a table instead of a list // Ok(Value::List { diff --git a/crates/nu_plugin_gstat/src/nu/mod.rs b/crates/nu_plugin_gstat/src/nu/mod.rs index e89112c878..6e09f468f0 100644 --- a/crates/nu_plugin_gstat/src/nu/mod.rs +++ b/crates/nu_plugin_gstat/src/nu/mod.rs @@ -27,6 +27,7 @@ impl SimplePluginCommand for GStat { fn signature(&self) -> Signature { Signature::build(PluginCommand::name(self)) + .switch("no-tag", "Disable git tag resolving", None) .optional("path", SyntaxShape::Filepath, "path to repo") .category(Category::Custom("prompt".to_string())) } @@ -41,6 +42,8 @@ impl SimplePluginCommand for GStat { let repo_path: Option> = call.opt(0)?; // eprintln!("input value: {:#?}", &input); let current_dir = engine.get_current_dir()?; - self.gstat(input, ¤t_dir, repo_path, call.head) + let disable_tag = call.has_flag("no-tag")?; + + self.gstat(input, ¤t_dir, repo_path, !disable_tag, call.head) } }