radicle_cli/commands/remote/
add.rs1use std::str::FromStr;
2
3use radicle::git;
4use radicle::git::RefString;
5use radicle::prelude::*;
6use radicle::Profile;
7use radicle_crypto::PublicKey;
8
9use crate::commands::checkout;
10use crate::commands::follow;
11use crate::commands::sync;
12use crate::node::SyncSettings;
13use crate::project::SetupRemote;
14
15pub fn run(
16 rid: RepoId,
17 nid: &PublicKey,
18 name: Option<RefString>,
19 tracking: Option<BranchName>,
20 profile: &Profile,
21 repo: &git::raw::Repository,
22 fetch: bool,
23 sync: bool,
24) -> anyhow::Result<()> {
25 if sync {
26 let mut node = radicle::Node::new(profile.socket());
27
28 if !profile.policies()?.is_following(nid)? {
29 let alias = name.as_ref().and_then(|n| Alias::from_str(n.as_str()).ok());
30
31 follow::follow(*nid, alias, &mut node, profile)?;
32 sync::fetch(
33 rid,
34 SyncSettings::default().with_profile(profile),
35 &mut node,
36 profile,
37 )?;
38 }
39 }
40 let aliases = profile.aliases();
41 let setup = SetupRemote {
42 rid,
43 tracking,
44 fetch,
45 repo,
46 };
47 checkout::setup_remote(&setup, nid, name, &aliases)?;
48
49 Ok(())
50}