Skip to content

Commit

Permalink
Add support for passing urls directly to bypass all remote repository…
Browse files Browse the repository at this point in the history
… logic. (#450)

This, however, still means a repository is required even though it won't
be used.
  • Loading branch information
Byron committed Aug 22, 2022
1 parent 7a17690 commit df3cf18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
11 changes: 7 additions & 4 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#[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;

#[git::protocol::maybe_async::maybe_async]
pub async fn refs(
repo: git::Repository,
name: Option<&str>,
url: Option<git::Url>,
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 {:?}",
Expand Down
4 changes: 3 additions & 1 deletion src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -107,6 +107,7 @@ pub fn main() -> Result<()> {
core::repository::remote::refs(
repository(Mode::Lenient)?,
name.as_deref(),
url,
format,
progress,
out,
Expand All @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -105,6 +107,10 @@ pub mod remote {
#[clap(long, short = 'n')]
pub name: Option<String>,

/// 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<git::Url>,

/// Subcommands
#[clap(subcommand)]
pub cmd: Subcommands,
Expand Down

0 comments on commit df3cf18

Please sign in to comment.