diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-03 13:08:56 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-04 12:48:37 +0000 |
| commit | a55d4150066456084fd18987acf014c18d0da976 (patch) | |
| tree | b6df894e60bb4fbc8854a76b8036b8a76922010b /src/bin | |
| parent | f91a0d00bafe2af1f6b6828c3de3d3e5d65153c3 (diff) | |
add nostr.repo-relay-only config to limit publishing to repo relays
Adds a git config key nostr.repo-relay-only that, when set to true, causes
nostr events to be sent only to the repository's own relays, skipping the
user's personal write relays and default/blaster relays. Useful for
repositories that should not broadcast to the maintainer's personal relay set.
Set persistently via \`git config nostr.repo-relay-only true\` or in one step
with \`ngit init --repo-relay-only\`.
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 13 | ||||
| -rw-r--r-- | src/bin/ngit/cli.rs | 3 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 24 |
3 files changed, 37 insertions, 3 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index ed0f7df..3b5e05d 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -402,6 +402,13 @@ async fn create_and_publish_events_and_proposals( | |||
| 402 | 402 | ||
| 403 | // TODO check whether tip of each branch pushed is on at least one git server | 403 | // TODO check whether tip of each branch pushed is on at least one git server |
| 404 | // before broadcasting the nostr state | 404 | // before broadcasting the nostr state |
| 405 | let repo_relay_only = | ||
| 406 | if let Ok(Some(v)) = git_repo.get_git_config_item("nostr.repo-relay-only", None) { | ||
| 407 | v == "true" | ||
| 408 | } else { | ||
| 409 | false | ||
| 410 | }; | ||
| 411 | |||
| 405 | let relay_results = if events.is_empty() { | 412 | let relay_results = if events.is_empty() { |
| 406 | vec![] | 413 | vec![] |
| 407 | } else { | 414 | } else { |
| @@ -409,7 +416,11 @@ async fn create_and_publish_events_and_proposals( | |||
| 409 | client, | 416 | client, |
| 410 | Some(git_repo.get_path()?), | 417 | Some(git_repo.get_path()?), |
| 411 | events, | 418 | events, |
| 412 | user_ref.relays.write(), | 419 | if repo_relay_only { |
| 420 | vec![] | ||
| 421 | } else { | ||
| 422 | user_ref.relays.write() | ||
| 423 | }, | ||
| 413 | repo_ref.relays.clone(), | 424 | repo_ref.relays.clone(), |
| 414 | true, | 425 | true, |
| 415 | false, | 426 | false, |
diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 164035b..68b18a7 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs | |||
| @@ -67,6 +67,9 @@ Or just for this repository: | |||
| 67 | 67 | ||
| 68 | Other useful settings: | 68 | Other useful settings: |
| 69 | - 'nostr.nostate true' to avoid publishing a state event when pushing to a nostr remote. | 69 | - 'nostr.nostate true' to avoid publishing a state event when pushing to a nostr remote. |
| 70 | - 'nostr.repo-relay-only true' to only publish nostr events to repo relays, skipping user and | ||
| 71 | default relays. Useful for repositories where you don't want to broadcast to your personal | ||
| 72 | relay set. Set via `git config nostr.repo-relay-only true` or `ngit init --repo-relay-only`. | ||
| 70 | - Login settings configured during `ngit account login`: | 73 | - Login settings configured during `ngit account login`: |
| 71 | - nostr.nsec - nsec or ncryptsec | 74 | - nostr.nsec - nsec or ncryptsec |
| 72 | - nostr.npub - used for ncryptsec and remote signer | 75 | - nostr.npub - used for ncryptsec and remote signer |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 021a33e..0554f32 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -430,6 +430,10 @@ pub struct SubCommandArgs { | |||
| 430 | #[clap(long)] | 430 | #[clap(long)] |
| 431 | /// usually root commit but will be more recent commit for forks | 431 | /// usually root commit but will be more recent commit for forks |
| 432 | earliest_unique_commit: Option<String>, | 432 | earliest_unique_commit: Option<String>, |
| 433 | #[clap(long)] | ||
| 434 | /// only publish nostr events to repo relays, not to user or default relays | ||
| 435 | /// (sets nostr.repo-relay-only in local git config) | ||
| 436 | repo_relay_only: bool, | ||
| 433 | } | 437 | } |
| 434 | 438 | ||
| 435 | impl SubCommandArgs { | 439 | impl SubCommandArgs { |
| @@ -444,6 +448,7 @@ impl SubCommandArgs { | |||
| 444 | || !self.other_maintainers.is_empty() | 448 | || !self.other_maintainers.is_empty() |
| 445 | || !self.hashtag.is_empty() | 449 | || !self.hashtag.is_empty() |
| 446 | || self.earliest_unique_commit.is_some() | 450 | || self.earliest_unique_commit.is_some() |
| 451 | || self.repo_relay_only | ||
| 447 | } | 452 | } |
| 448 | } | 453 | } |
| 449 | 454 | ||
| @@ -1266,11 +1271,21 @@ async fn publish_and_finalize( | |||
| 1266 | // Step 5: Publish events | 1271 | // Step 5: Publish events |
| 1267 | client.set_signer(signer).await; | 1272 | client.set_signer(signer).await; |
| 1268 | 1273 | ||
| 1274 | let repo_relay_only = git_repo | ||
| 1275 | .get_git_config_item("nostr.repo-relay-only", None) | ||
| 1276 | .ok() | ||
| 1277 | .flatten() | ||
| 1278 | .is_some_and(|s| s == "true"); | ||
| 1279 | |||
| 1269 | let _ = send_events( | 1280 | let _ = send_events( |
| 1270 | client, | 1281 | client, |
| 1271 | Some(git_repo_path), | 1282 | Some(git_repo_path), |
| 1272 | events, | 1283 | events, |
| 1273 | user_ref.relays.write(), | 1284 | if repo_relay_only { |
| 1285 | vec![] | ||
| 1286 | } else { | ||
| 1287 | user_ref.relays.write() | ||
| 1288 | }, | ||
| 1274 | fields.relays.clone(), | 1289 | fields.relays.clone(), |
| 1275 | !cli.disable_cli_spinners, | 1290 | !cli.disable_cli_spinners, |
| 1276 | false, | 1291 | false, |
| @@ -1522,7 +1537,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 1522 | cli_args.interactive, | 1537 | cli_args.interactive, |
| 1523 | )?; | 1538 | )?; |
| 1524 | 1539 | ||
| 1525 | // Phase 6: Build and publish | 1540 | // Phase 6: Persist --repo-relay-only flag to local git config if supplied |
| 1541 | if args.repo_relay_only { | ||
| 1542 | git_repo.save_git_config_item("nostr.repo-relay-only", "true", false)?; | ||
| 1543 | } | ||
| 1544 | |||
| 1545 | // Phase 7: Build and publish | ||
| 1526 | publish_and_finalize( | 1546 | publish_and_finalize( |
| 1527 | fields, | 1547 | fields, |
| 1528 | signer, | 1548 | signer, |