cli: Setup tracking branch on `rad remote add`

This commit is contained in:
Alexis Sellier 2023-06-12 12:44:43 +02:00
parent e9ef0f4aa4
commit ec064891cd
No known key found for this signature in database
5 changed files with 38 additions and 2 deletions

View File

@ -60,6 +60,7 @@ We can then setup a git remote for `bob`:
```
$ rad remote add z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob
✓ Remote bob added
✓ Remote-tracking branch bob/master created for z6Mkt67…v4N1tRk
```
And fetch his refs:

View File

@ -3,6 +3,7 @@ Now, let's add a bob as a new remote:
```
$ rad remote add did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob
✓ Remote bob added
✓ Remote-tracking branch bob/master created for z6Mkt67…v4N1tRk
```
Now, we can see that there is a new remote in the list of remotes:
@ -17,11 +18,29 @@ rad z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi (push)
You can see both `bob` and `rad` as remotes. The `rad` remote is our personal
remote of the project.
For the remote-tracking branch to work, we fetch bob:
``` (stderr)
$ git fetch bob
From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
* [new branch] master -> bob/master
```
We can now see the remote-tracking branch that was setup:
```
$ git branch -r -v
bob/master f2de534 Second commit
rad/master f2de534 Second commit
```
When we're finished with the `bob` remote, we can remove it:
```
$ rad remote rm bob
✓ Remote `bob` removed
$ git branch -r -v
rad/master f2de534 Second commit
```
Now, add another time `bob` but without specify the `name`, so we should be
@ -30,4 +49,5 @@ able to fetch the node alias from our db!
```
$ rad remote add did:key:z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk
✓ Remote bob added
✓ Remote-tracking branch bob/master created for z6Mkt67…v4N1tRk
```

View File

@ -16,6 +16,7 @@ peer. Upcoming versions of radicle will not require this step.
```
$ rad remote add z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob
✓ Remote bob added
✓ Remote-tracking branch bob/master created for z6Mkt67…v4N1tRk
```
``` (stderr)

View File

@ -12,6 +12,7 @@ use anyhow::anyhow;
use radicle::git::RefString;
use radicle::prelude::NodeId;
use radicle::storage::ReadStorage;
use crate::terminal::args;
use crate::terminal::{Args, Context, Help};
@ -119,8 +120,12 @@ pub fn run(options: Options, ctx: impl Context) -> anyhow::Result<()> {
let profile = ctx.profile()?;
match options.op {
// TODO: Support remote-tracking.
Operation::Add { ref id, name } => self::add::run(rid, id, name, None, &profile, &working)?,
Operation::Add { ref id, name } => {
let proj = profile.storage.repository(rid)?.project()?;
let branch = proj.default_branch();
self::add::run(rid, id, name, Some(branch.clone()), &profile, &working)?
}
Operation::Rm { ref name } => self::rm::run(name, &working)?,
Operation::List => self::list::run(&working)?,
};

View File

@ -832,6 +832,7 @@ fn rad_remote() {
let bob = environment.node("bob");
let working = environment.tmp().join("working");
let home = alice.home.clone();
let rid = Id::from_str("z42hL2jL4XNk6K8oHQaSWfMgCL7ji").unwrap();
// Setup a test repository.
fixtures::repository(working.join("alice"));
@ -844,11 +845,19 @@ fn rad_remote() {
.unwrap();
let mut alice = alice.spawn(Config::default());
let mut bob = bob.spawn(Config::default());
alice
.handle
.track_node(bob.id, Some("bob".to_owned()))
.unwrap();
bob.connect(&alice);
bob.routes_to(&[(rid, alice.id)]);
bob.rad("clone", &[rid.to_string().as_str()], &working)
.unwrap();
alice.has_inventory_of(&rid, &bob.id);
test(
"examples/rad-remote.md",
working.join("alice"),