From 2922a0de25261fd025c7aef03e2331904a274dbf Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 17 May 2026 17:10:29 -0300 Subject: [PATCH] git: support nostr://... URLs without requiring the component. --- git.go | 50 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/git.go b/git.go index 1402889..25f91f5 100644 --- a/git.go +++ b/git.go @@ -369,7 +369,7 @@ aside from those, there is also: { Name: "clone", Usage: "clone a NIP-34 repository from a nostr:// URI", - Description: `the parameter maybe in the form "/", ngit-style like "nostr:////" or an "naddr1..." code.`, + Description: `the parameter maybe in the form "/", ngit-style like "nostr:////" or "nostr:///" or an "naddr1..." code.`, ArgsUsage: " [directory]", Action: func(ctx context.Context, c *cli.Command) error { args := c.Args() @@ -2633,30 +2633,40 @@ func parseRepositoryAddress( } // format 2: nostr://// (ngit-style) + // format 2b: nostr:/// (without relay) if strings.HasPrefix(address, "nostr://") { parts := strings.Split(address, "/") - if len(parts) != 5 { + if len(parts) == 5 { + // nostr://// + owner, err = parsePubKey(parts[2]) + if err != nil { + return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err) + } + + relayHost := parts[3] + identifier = parts[4] + + if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") { + relayHints = []string{relayHost} + } else { + relayHints = []string{"wss://" + relayHost} + } + + return owner, identifier, relayHints, nil + } else if len(parts) == 4 { + // nostr:/// + owner, err = parsePubKey(parts[2]) + if err != nil { + return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err) + } + + identifier = parts[3] + return owner, identifier, nil, nil + } else { return nostr.PubKey{}, "", nil, fmt.Errorf( - "invalid nostr URL format, expected nostr:////, got: %s", address, + "invalid nostr URL format, expected nostr:/// or nostr:////, got: %s", address, ) } - - owner, err = parsePubKey(parts[2]) - if err != nil { - return nostr.PubKey{}, "", nil, fmt.Errorf("invalid owner in URL: %w", err) - } - - relayHost := parts[3] - identifier = parts[4] - - // construct relay hint from hostname - if strings.HasPrefix(relayHost, "wss:") || strings.HasPrefix(relayHost, "ws:") { - relayHints = []string{relayHost} - } else { - relayHints = []string{"wss://" + relayHost} - } - - return owner, identifier, relayHints, nil } // format 3: /