From 06ebbf7c73b64225ae083bb3134f7c7c630c5565 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 17 Feb 2026 11:34:28 +0000 Subject: fix: require both title and description push-options or neither Previously, providing only one of title or description would silently ignore both. Now returns a clear error message. --- src/bin/git_remote_nostr/main.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index e57dff7..61c439d 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -30,6 +30,21 @@ struct PushOptions { description: Option, } +impl PushOptions { + fn validate(&self) -> Result> { + match (&self.title, &self.description) { + (Some(t), Some(d)) => Ok(Some((t.clone(), d.clone()))), + (Some(_), None) => bail!( + "error: 'title' push-option provided without 'description'. Both title and description are required together, or neither to use defaults." + ), + (None, Some(_)) => bail!( + "error: 'description' push-option provided without 'title'. Both title and description are required together, or neither to use defaults." + ), + (None, None) => Ok(None), + } + } +} + mod fetch; mod list; mod push; @@ -110,6 +125,7 @@ async fn main() -> Result<()> { fetch::run_fetch(&git_repo, &repo_ref, &stdin, oid, refstr).await?; } ["push", refspec] => { + let title_description = push_options.validate()?; push::run_push( &git_repo, &repo_ref, @@ -117,7 +133,7 @@ async fn main() -> Result<()> { refspec, &client, list_outputs.clone(), - push_options.title.as_ref().zip(push_options.description.as_ref()).map(|(t, d)| (t.clone(), d.clone())), + title_description, ) .await?; push_options = PushOptions::default(); -- cgit v1.2.3