diff --git a/gitoxide-core/src/repository/remote.rs b/gitoxide-core/src/repository/remote.rs index 6eaf5ef397c..74b15c5faf5 100644 --- a/gitoxide-core/src/repository/remote.rs +++ b/gitoxide-core/src/repository/remote.rs @@ -1,7 +1,7 @@ #[cfg(any(feature = "blocking-client", feature = "async-client"))] mod net { use crate::OutputFormat; - use anyhow::Context; + use anyhow::{bail, Context}; use git_repository as git; use git_repository::protocol::fetch; @@ -9,16 +9,19 @@ mod net { pub async fn refs( repo: git::Repository, name: Option<&str>, + url: Option, format: OutputFormat, mut progress: impl git::Progress, out: impl std::io::Write, ) -> anyhow::Result<()> { - let remote = match name { - Some(name) => repo.find_remote(name)?, - None => repo + let remote = match (name, url) { + (Some(name), None) => repo.find_remote(name)?, + (None, None) => repo .head()? .into_remote(git::remote::Direction::Fetch) .context("Cannot find a remote for unborn branch")??, + (None, Some(url)) => repo.remote_at(url)?, + (Some(_), Some(_)) => bail!("Must not set both the remote name and the url - they are mutually exclusive"), }; progress.info(format!( "Connecting to {:?}", diff --git a/src/plumbing/main.rs b/src/plumbing/main.rs index 023287119b3..d71a797b647 100644 --- a/src/plumbing/main.rs +++ b/src/plumbing/main.rs @@ -92,7 +92,7 @@ pub fn main() -> Result<()> { match cmd { #[cfg_attr(feature = "small", allow(unused_variables))] - Subcommands::Remote(remote::Platform { name, cmd }) => match cmd { + Subcommands::Remote(remote::Platform { name, url, cmd }) => match cmd { #[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))] remote::Subcommands::Refs => { #[cfg(feature = "gitoxide-core-blocking-client")] @@ -107,6 +107,7 @@ pub fn main() -> Result<()> { core::repository::remote::refs( repository(Mode::Lenient)?, name.as_deref(), + url, format, progress, out, @@ -121,6 +122,7 @@ pub fn main() -> Result<()> { futures_lite::future::block_on(core::repository::remote::refs( repository(Mode::Lenient)?, name.as_deref(), + url, format, progress, std::io::stdout(), diff --git a/src/plumbing/options.rs b/src/plumbing/options.rs index a7a579d459b..d5627f3acf3 100644 --- a/src/plumbing/options.rs +++ b/src/plumbing/options.rs @@ -97,6 +97,8 @@ pub mod config { } pub mod remote { + use git_repository as git; + #[derive(Debug, clap::Parser)] pub struct Platform { /// The name of the remote to connect to. @@ -105,6 +107,10 @@ pub mod remote { #[clap(long, short = 'n')] pub name: Option, + /// Connect directly to the given URL, forgoing any configuration from the repository. + #[clap(long, short = 'u', conflicts_with("name"), parse(try_from_os_str = std::convert::TryFrom::try_from))] + pub url: Option, + /// Subcommands #[clap(subcommand)] pub cmd: Subcommands,