From f26adabdbff401e14e174c2d8254c9178a41a7a8 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 19 Apr 2023 11:37:14 +0100 Subject: [PATCH] cli: add rad fork example test Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-cli/examples/rad-fork.md | 49 ++++++++++++++++++++++++++++++++ radicle-cli/tests/commands.rs | 41 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 radicle-cli/examples/rad-fork.md diff --git a/radicle-cli/examples/rad-fork.md b/radicle-cli/examples/rad-fork.md new file mode 100644 index 00000000..8e38e908 --- /dev/null +++ b/radicle-cli/examples/rad-fork.md @@ -0,0 +1,49 @@ +If we have fetched a project, then we do not have a fork of the +repository in the storage, i.e. there is no ref hierarchy for our +NID. This is demonstrated below where our NID is +`z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk`: + +``` +$ rad inspect rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --refs +. +`-- z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi + `-- refs + |-- heads + | `-- master + `-- rad + |-- id + `-- sigrefs +``` + +To remedy this, we can use the `rad fork` command for the project we +wish to fork: + +``` +$ rad fork rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji +✓ Forked project rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji for z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk +``` + +Now, if we `rad inspect` the project's refs again we will see that we +have a copy of the main set of refs: + +``` +$ rad inspect rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji --refs +. +|-- z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi +| `-- refs +| |-- heads +| | `-- master +| `-- rad +| |-- id +| `-- sigrefs +`-- z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk + `-- refs + |-- heads + | `-- master + `-- rad + |-- id + `-- sigrefs +``` + +We are now able to setup a remote in our own working copy of the +project and push to our own fork. diff --git a/radicle-cli/tests/commands.rs b/radicle-cli/tests/commands.rs index f9a317c5..cf0a55b6 100644 --- a/radicle-cli/tests/commands.rs +++ b/radicle-cli/tests/commands.rs @@ -428,6 +428,47 @@ fn rad_fetch() { .unwrap(); } +#[test] +fn rad_fork() { + let mut environment = Environment::new(); + let working = environment.tmp().join("working"); + let alice = environment.node("alice"); + let bob = environment.node("bob"); + + let mut alice = alice.spawn(Config::default()); + let bob = bob.spawn(Config::default()); + + alice.connect(&bob); + fixtures::repository(working.join("alice")); + + // Alice initializes a repo after her node has started, and after bob has connected to it. + test( + "examples/rad-init-sync.md", + &working.join("alice"), + Some(&alice.home), + [], + ) + .unwrap(); + + // Wait for bob to get any updates to the routing table. + bob.converge([&alice]); + + test( + "examples/rad-fetch.md", + working.join("bob"), + Some(&bob.home), + [], + ) + .unwrap(); + test( + "examples/rad-fork.md", + working.join("bob"), + Some(&bob.home), + [], + ) + .unwrap(); +} + #[test] // User tries to clone; no seeds are available, but user has the repo locally. fn test_clone_without_seeds() {