diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-17 11:34:28 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-17 11:38:28 +0000 |
| commit | 06ebbf7c73b64225ae083bb3134f7c7c630c5565 (patch) | |
| tree | 77e43bd00db95ca130b3e55ce825dcd93c3fc3f3 /src/bin/git_remote_nostr/main.rs | |
| parent | fe5addc2a61022824e83c3523a83fce7690ca8e8 (diff) | |
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.
Diffstat (limited to 'src/bin/git_remote_nostr/main.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/main.rs | 18 |
1 files changed, 17 insertions, 1 deletions
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 { | |||
| 30 | description: Option<String>, | 30 | description: Option<String>, |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | impl PushOptions { | ||
| 34 | fn validate(&self) -> Result<Option<(String, String)>> { | ||
| 35 | match (&self.title, &self.description) { | ||
| 36 | (Some(t), Some(d)) => Ok(Some((t.clone(), d.clone()))), | ||
| 37 | (Some(_), None) => bail!( | ||
| 38 | "error: 'title' push-option provided without 'description'. Both title and description are required together, or neither to use defaults." | ||
| 39 | ), | ||
| 40 | (None, Some(_)) => bail!( | ||
| 41 | "error: 'description' push-option provided without 'title'. Both title and description are required together, or neither to use defaults." | ||
| 42 | ), | ||
| 43 | (None, None) => Ok(None), | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 33 | mod fetch; | 48 | mod fetch; |
| 34 | mod list; | 49 | mod list; |
| 35 | mod push; | 50 | mod push; |
| @@ -110,6 +125,7 @@ async fn main() -> Result<()> { | |||
| 110 | fetch::run_fetch(&git_repo, &repo_ref, &stdin, oid, refstr).await?; | 125 | fetch::run_fetch(&git_repo, &repo_ref, &stdin, oid, refstr).await?; |
| 111 | } | 126 | } |
| 112 | ["push", refspec] => { | 127 | ["push", refspec] => { |
| 128 | let title_description = push_options.validate()?; | ||
| 113 | push::run_push( | 129 | push::run_push( |
| 114 | &git_repo, | 130 | &git_repo, |
| 115 | &repo_ref, | 131 | &repo_ref, |
| @@ -117,7 +133,7 @@ async fn main() -> Result<()> { | |||
| 117 | refspec, | 133 | refspec, |
| 118 | &client, | 134 | &client, |
| 119 | list_outputs.clone(), | 135 | list_outputs.clone(), |
| 120 | push_options.title.as_ref().zip(push_options.description.as_ref()).map(|(t, d)| (t.clone(), d.clone())), | 136 | title_description, |
| 121 | ) | 137 | ) |
| 122 | .await?; | 138 | .await?; |
| 123 | push_options = PushOptions::default(); | 139 | push_options = PushOptions::default(); |