Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Correctly setup remote tracking branch
Alexis Sellier committed 3 years ago
commit fdad6358fce828763a712cea63fa0738636b111e
parent cdc3c8a2652a84ec9aa0eea41b3c2da76c4718fd
2 files changed +12 -12
modified radicle-cli/src/project.rs
@@ -1,6 +1,6 @@
use radicle::git::raw::Remote;
+
use radicle::git::RefString;
use radicle::prelude::*;
-
use radicle::rad;

use crate::git;

@@ -20,10 +20,9 @@ pub struct SetupRemote<'a> {

impl<'a> SetupRemote<'a> {
    /// 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 mut remote =
-
            radicle::git::configure_remote(self.repo, rad::peer_remote(&node).as_str(), &url)?;
+
        let mut remote = radicle::git::configure_remote(self.repo, &node.to_string(), &url)?;

        // Fetch the refs into the working copy.
        if self.fetch {
@@ -31,9 +30,16 @@ impl<'a> SetupRemote<'a> {
        }
        // Setup remote-tracking branch.
        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)
    }
modified radicle/src/rad.rs
@@ -11,7 +11,6 @@ use crate::git;
use crate::identity::doc;
use crate::identity::doc::{DocError, Id};
use crate::identity::project::Project;
-
use crate::node::NodeId;
use crate::node::{self, FetchLookup};
use crate::storage::git::transport::{self, remote};
use crate::storage::git::{ProjectError, Repository, Storage};
@@ -22,11 +21,6 @@ use crate::{identity, storage};
/// Name of the radicle storage remote.
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)]
pub enum InitError {
    #[error("doc: {0}")]