cli: Correctly setup remote tracking branch

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier 2023-01-25 13:00:22 +01:00
parent cdc3c8a265
commit fdad6358fc
No known key found for this signature in database
2 changed files with 12 additions and 12 deletions

View File

@ -1,6 +1,6 @@
use radicle::git::raw::Remote; use radicle::git::raw::Remote;
use radicle::git::RefString;
use radicle::prelude::*; use radicle::prelude::*;
use radicle::rad;
use crate::git; use crate::git;
@ -20,10 +20,9 @@ pub struct SetupRemote<'a> {
impl<'a> SetupRemote<'a> { impl<'a> SetupRemote<'a> {
/// Run the setup for the given peer. /// Run the setup for the given peer.
pub fn run(&self, node: NodeId) -> anyhow::Result<Option<(Remote, String)>> { pub fn run(&self, node: NodeId) -> anyhow::Result<Option<(Remote, RefString)>> {
let url = radicle::git::Url::from(self.project).with_namespace(node); let url = radicle::git::Url::from(self.project).with_namespace(node);
let mut remote = let mut remote = radicle::git::configure_remote(self.repo, &node.to_string(), &url)?;
radicle::git::configure_remote(self.repo, rad::peer_remote(&node).as_str(), &url)?;
// Fetch the refs into the working copy. // Fetch the refs into the working copy.
if self.fetch { if self.fetch {
@ -31,9 +30,16 @@ impl<'a> SetupRemote<'a> {
} }
// Setup remote-tracking branch. // Setup remote-tracking branch.
if self.tracking { if self.tracking {
let branch = git::set_tracking(self.repo, &node, &self.default_branch)?; // SAFETY: Node IDs are valid ref strings.
let node_ref = RefString::try_from(node.to_string()).unwrap();
let node_ref = node_ref.as_refstr();
let branch_name = node_ref.join(&self.default_branch);
let local_branch = radicle::git::refs::workdir::branch(
node_ref.join(&self.default_branch).as_refstr(),
);
radicle::git::set_upstream(self.repo, &node.to_string(), &branch_name, &local_branch)?;
return Ok(Some((remote, branch))); return Ok(Some((remote, branch_name)));
} }
Ok(None) Ok(None)
} }

View File

@ -11,7 +11,6 @@ use crate::git;
use crate::identity::doc; use crate::identity::doc;
use crate::identity::doc::{DocError, Id}; use crate::identity::doc::{DocError, Id};
use crate::identity::project::Project; use crate::identity::project::Project;
use crate::node::NodeId;
use crate::node::{self, FetchLookup}; use crate::node::{self, FetchLookup};
use crate::storage::git::transport::{self, remote}; use crate::storage::git::transport::{self, remote};
use crate::storage::git::{ProjectError, Repository, Storage}; use crate::storage::git::{ProjectError, Repository, Storage};
@ -22,11 +21,6 @@ use crate::{identity, storage};
/// Name of the radicle storage remote. /// Name of the radicle storage remote.
pub static REMOTE_NAME: Lazy<git::RefString> = Lazy::new(|| git::refname!("rad")); pub static REMOTE_NAME: Lazy<git::RefString> = Lazy::new(|| git::refname!("rad"));
/// Radicle remote name for peer, eg. `rad/<node-id>`
pub fn peer_remote(peer: &NodeId) -> String {
format!("rad/{peer}")
}
#[derive(Error, Debug)] #[derive(Error, Debug)]
pub enum InitError { pub enum InitError {
#[error("doc: {0}")] #[error("doc: {0}")]