From a55d4150066456084fd18987acf014c18d0da976 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 3 Mar 2026 13:08:56 +0000 Subject: 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\`. --- CHANGELOG.md | 4 ++++ src/bin/git_remote_nostr/push.rs | 13 ++++++++++++- src/bin/ngit/cli.rs | 3 +++ src/bin/ngit/sub_commands/init.rs | 24 ++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6907db..8b6b4c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `nostr.repo-relay-only` git config key: when set to `true`, nostr events are sent only to the repository's own relays, skipping the user's personal write relays and default/blaster relays; set persistently via `git config nostr.repo-relay-only true` or in one step with `ngit init --repo-relay-only` + ## [2.2.3] - 2026-02-27 ### Fixed 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( // TODO check whether tip of each branch pushed is on at least one git server // before broadcasting the nostr state + let repo_relay_only = + if let Ok(Some(v)) = git_repo.get_git_config_item("nostr.repo-relay-only", None) { + v == "true" + } else { + false + }; + let relay_results = if events.is_empty() { vec![] } else { @@ -409,7 +416,11 @@ async fn create_and_publish_events_and_proposals( client, Some(git_repo.get_path()?), events, - user_ref.relays.write(), + if repo_relay_only { + vec![] + } else { + user_ref.relays.write() + }, repo_ref.relays.clone(), true, 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: Other useful settings: - 'nostr.nostate true' to avoid publishing a state event when pushing to a nostr remote. + - 'nostr.repo-relay-only true' to only publish nostr events to repo relays, skipping user and + default relays. Useful for repositories where you don't want to broadcast to your personal + relay set. Set via `git config nostr.repo-relay-only true` or `ngit init --repo-relay-only`. - Login settings configured during `ngit account login`: - nostr.nsec - nsec or ncryptsec - 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 { #[clap(long)] /// usually root commit but will be more recent commit for forks earliest_unique_commit: Option, + #[clap(long)] + /// only publish nostr events to repo relays, not to user or default relays + /// (sets nostr.repo-relay-only in local git config) + repo_relay_only: bool, } impl SubCommandArgs { @@ -444,6 +448,7 @@ impl SubCommandArgs { || !self.other_maintainers.is_empty() || !self.hashtag.is_empty() || self.earliest_unique_commit.is_some() + || self.repo_relay_only } } @@ -1266,11 +1271,21 @@ async fn publish_and_finalize( // Step 5: Publish events client.set_signer(signer).await; + let repo_relay_only = git_repo + .get_git_config_item("nostr.repo-relay-only", None) + .ok() + .flatten() + .is_some_and(|s| s == "true"); + let _ = send_events( client, Some(git_repo_path), events, - user_ref.relays.write(), + if repo_relay_only { + vec![] + } else { + user_ref.relays.write() + }, fields.relays.clone(), !cli.disable_cli_spinners, false, @@ -1522,7 +1537,12 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { cli_args.interactive, )?; - // Phase 6: Build and publish + // Phase 6: Persist --repo-relay-only flag to local git config if supplied + if args.repo_relay_only { + git_repo.save_git_config_item("nostr.repo-relay-only", "true", false)?; + } + + // Phase 7: Build and publish publish_and_finalize( fields, signer, -- cgit v1.2.3