mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
cli: Add canonical remote to init and checkout
Add a remote that points to the canonical upstream.
This commit is contained in:
@@ -3,33 +3,26 @@ use radicle_term::{Element, Table};
|
||||
use crate::git;
|
||||
use crate::terminal as term;
|
||||
|
||||
#[inline]
|
||||
fn format_direction(d: &git::Direction) -> String {
|
||||
match d {
|
||||
git::Direction::Fetch => "fetch".to_owned(),
|
||||
git::Direction::Push => "push".to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(repo: &git::Repository) -> anyhow::Result<()> {
|
||||
let mut table = Table::default();
|
||||
let remotes = git::rad_remotes(repo)?;
|
||||
for r in remotes {
|
||||
for spec in r.refspecs() {
|
||||
let dir = spec.direction();
|
||||
let url = r.url.clone();
|
||||
let name = r.name.clone();
|
||||
let nid_row = url.namespace.map_or(
|
||||
term::format::dim("This is the canonical upstream".to_string()),
|
||||
|namespace| term::format::highlight(namespace.to_string()),
|
||||
for (dir, url) in [("fetch", Some(r.url)), ("push", r.pushurl)] {
|
||||
let Some(url) = url else {
|
||||
continue;
|
||||
};
|
||||
let nid = url.namespace.map_or(
|
||||
term::format::dim("the canonical upstream".to_string()).italic(),
|
||||
|namespace| term::format::tertiary(namespace.to_string()),
|
||||
);
|
||||
table.push([
|
||||
term::format::badge_positive(format_direction(&dir)),
|
||||
term::format::highlight(name.to_owned()),
|
||||
nid_row,
|
||||
term::format::bold(r.name.clone()),
|
||||
nid,
|
||||
term::format::parens(term::format::secondary(dir.to_owned())),
|
||||
]);
|
||||
}
|
||||
}
|
||||
table.print();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -76,13 +76,10 @@ pub enum RemoteError {
|
||||
pub struct Remote<'a> {
|
||||
pub(crate) name: String,
|
||||
pub(crate) url: radicle::git::Url,
|
||||
inner: git2::Remote<'a>,
|
||||
}
|
||||
pub(crate) pushurl: Option<radicle::git::Url>,
|
||||
|
||||
impl Remote<'_> {
|
||||
pub fn refspecs(&self) -> git2::Refspecs {
|
||||
self.inner.refspecs()
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
inner: git2::Remote<'a>,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<git2::Remote<'a>> for Remote<'a> {
|
||||
@@ -92,10 +89,16 @@ impl<'a> TryFrom<git2::Remote<'a>> for Remote<'a> {
|
||||
let url = value.url().map_or(Err(RemoteError::MissingUrl), |url| {
|
||||
Ok(radicle::git::Url::from_str(url)?)
|
||||
})?;
|
||||
let pushurl = value
|
||||
.pushurl()
|
||||
.map(radicle::git::Url::from_str)
|
||||
.transpose()?;
|
||||
let name = value.name().ok_or(RemoteError::MissingName)?;
|
||||
|
||||
Ok(Self {
|
||||
name: name.to_owned(),
|
||||
url,
|
||||
pushurl,
|
||||
inner: value,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl<'a> SetupRemote<'a> {
|
||||
/// Run the setup for the given peer.
|
||||
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, &node.to_string(), &url)?;
|
||||
let mut remote = radicle::git::configure_remote(self.repo, &node.to_string(), &url, &url)?;
|
||||
|
||||
// Fetch the refs into the working copy.
|
||||
if self.fetch {
|
||||
|
||||
Reference in New Issue
Block a user