From 04bfbca15d5fd6b8ae5d540a8c3166af463db653 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Wed, 3 Jan 2024 14:07:19 +0100 Subject: [PATCH] cli: Support `--seed` on `rad clone` Allows specifying one or more seeds to clone from. This is useful for cloning private repositories which are not in the routing table. --- .../examples/rad-init-private-clone-seed.md | 45 +++++++++++++++++ .../examples/rad-init-private-clone.md | 7 ++- radicle-cli/src/commands/clone.rs | 49 +++++++++++++++---- radicle-cli/tests/commands.rs | 41 ++++++++++++++++ 4 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 radicle-cli/examples/rad-init-private-clone-seed.md diff --git a/radicle-cli/examples/rad-init-private-clone-seed.md b/radicle-cli/examples/rad-init-private-clone-seed.md new file mode 100644 index 00000000..083dea07 --- /dev/null +++ b/radicle-cli/examples/rad-init-private-clone-seed.md @@ -0,0 +1,45 @@ +Given a private repo `rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu` belonging to Alice, +Alice allows Bob to fetch it, and Bob, without the updated identity document +is able to fetch it by specifiying Alice as a seed. + +``` ~alice +$ rad id update --title "Allow Bob" --description "" --allow did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk -q +... +$ rad inspect --identity +{ + "payload": { + "xyz.radicle.project": { + "defaultBranch": "master", + "description": "radicle heartwood protocol & stack", + "name": "heartwood" + } + }, + "delegates": [ + "did:key:z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi" + ], + "threshold": 1, + "visibility": { + "type": "private", + "allow": [ + "did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk" + ] + } +} +``` + +``` ~bob +$ rad ls --all --private +$ rad clone rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --seed z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi --timeout 1 +✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'all' +✓ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi.. +✓ Creating checkout in ./heartwood.. +✓ Remote alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi added +✓ Remote-tracking branch alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/master created for z6MknSL…StBU8Vi +✓ Repository successfully cloned under [...]/.radicle/heartwood/ +╭────────────────────────────────────╮ +│ heartwood │ +│ radicle heartwood protocol & stack │ +│ 0 issues · 0 patches │ +╰────────────────────────────────────╯ +Run `cd ./heartwood` to go to the project directory. +``` diff --git a/radicle-cli/examples/rad-init-private-clone.md b/radicle-cli/examples/rad-init-private-clone.md index 12eee32f..b2a35737 100644 --- a/radicle-cli/examples/rad-init-private-clone.md +++ b/radicle-cli/examples/rad-init-private-clone.md @@ -2,14 +2,13 @@ Given a private repo `rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu` belonging to Alice, Bob tries to fetch it, and even though he's connected to Alice, it fails. ``` ~bob -$ rad seed rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --scope followed -✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'followed' $ rad ls ``` ``` ~bob (fail) -$ rad sync rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --fetch --seed z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi --timeout 1 +$ rad clone rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu --seed z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi --timeout 1 +✓ Seeding policy updated for rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu with scope 'all' ✗ Fetching rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu from z6MknSL…StBU8Vi.. error: failed to perform fetch handshake -✗ Error: repository fetch from 1 seed(s) failed +✗ Error: repository rad:z2ug5mwNKZB8KGpBDRTrWHAMbvHCu not found ``` She allows Bob to view the repository. And when she syncs, one node (Bob) gets diff --git a/radicle-cli/src/commands/clone.rs b/radicle-cli/src/commands/clone.rs index 592069a2..184d41b7 100644 --- a/radicle-cli/src/commands/clone.rs +++ b/radicle-cli/src/commands/clone.rs @@ -36,10 +36,18 @@ Usage rad clone [] [--scope ] [