Skip to content

Commit

Permalink
feat!: remove gix remote --url in favor of determining the intentio…
Browse files Browse the repository at this point in the history
…n similar to `git fetch` (#450)
  • Loading branch information
Byron committed Oct 2, 2022
1 parent 8c7351c commit 92bbe33
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 35 deletions.
4 changes: 1 addition & 3 deletions gitoxide-core/src/repository/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ pub struct Options {
pub format: OutputFormat,
pub dry_run: bool,
pub remote: Option<String>,
pub url: Option<git::Url>,
/// If non-empty, override all ref-specs otherwise configured in the remote
pub ref_specs: Vec<BString>,
}
Expand All @@ -27,11 +26,10 @@ pub(crate) mod function {
format,
dry_run,
remote,
url,
ref_specs,
}: Options,
) -> anyhow::Result<()> {
let _remote = crate::repository::remote::by_name_or_url(&repo, remote.as_deref(), url)?;
let _remote = crate::repository::remote::by_name_or_url(&repo, remote.as_deref())?;
todo!()
}
}
33 changes: 17 additions & 16 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ mod refs_impl {
Tracking { ref_specs: Vec<BString> },
}

pub struct Context {
pub struct Options {
pub format: OutputFormat,
pub name: Option<String>,
pub url: Option<git_repository::Url>,
pub name_or_url: Option<String>,
pub handshake_info: bool,
}

Expand All @@ -38,15 +37,14 @@ mod refs_impl {
mut progress: impl git::Progress,
mut out: impl std::io::Write,
err: impl std::io::Write,
refs::Context {
refs::Options {
format,
name,
url,
name_or_url,
handshake_info,
}: refs::Context,
}: refs::Options,
) -> anyhow::Result<()> {
use anyhow::Context;
let mut remote = by_name_or_url(&repo, name.as_deref(), url)?;
let mut remote = by_name_or_url(&repo, name_or_url.as_deref())?;
if let refs::Kind::Tracking { ref_specs, .. } = &kind {
if format != OutputFormat::Human {
bail!("JSON output isn't yet supported for listing ref-mappings.");
Expand Down Expand Up @@ -255,17 +253,20 @@ use git_repository as git;

pub(crate) fn by_name_or_url<'repo>(
repo: &'repo git::Repository,
name: Option<&str>,
url: Option<git::Url>,
name_or_url: Option<&str>,
) -> anyhow::Result<git::Remote<'repo>> {
use anyhow::{bail, Context};
Ok(match (name, url) {
(Some(name), None) => repo.find_remote(&name)?,
(None, None) => repo
use anyhow::Context;
Ok(match name_or_url {
Some(name) => {
if name.contains('/') {
repo.remote_at(git::url::parse(name.into())?)?
} else {
repo.find_remote(&name)?
}
}
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"),
})
}
8 changes: 2 additions & 6 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ pub fn main() -> Result<()> {
dry_run,
remote,
ref_spec,
url,
}) => {
let opts = core::repository::fetch::Options {
format,
dry_run,
remote,
ref_specs: ref_spec,
url,
};
prepare_and_run(
"fetch",
Expand All @@ -150,7 +148,6 @@ pub fn main() -> Result<()> {
#[cfg_attr(feature = "small", allow(unused_variables))]
Subcommands::Remote(remote::Platform {
name,
url,
cmd,
handshake_info,
}) => match cmd {
Expand All @@ -162,9 +159,8 @@ pub fn main() -> Result<()> {
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
}
};
let context = core::repository::remote::refs::Context {
name,
url,
let context = core::repository::remote::refs::Options {
name_or_url: name,
format,
handshake_info,
};
Expand Down
12 changes: 2 additions & 10 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,12 @@ pub mod fetch {
#[clap(long, short = 'n')]
pub dry_run: bool,

/// The name of the remote to connect to.
/// The name of the remote to connect to, or the url of the remote to connect to directly.
///
/// If unset, the current branch will determine the remote.
#[clap(long, short = 'r')]
pub remote: Option<String>,

/// Connect directly to the given URL, forgoing any configuration from the repository.
#[clap(long, short = 'u', conflicts_with("remote"), parse(try_from_os_str = std::convert::TryFrom::try_from))]
pub url: Option<git::Url>,

/// Override the built-in and configured ref-specs with one or more of the given ones.
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
pub ref_spec: Vec<git_repository::bstr::BString>,
Expand All @@ -144,16 +140,12 @@ pub mod remote {

#[derive(Debug, clap::Parser)]
pub struct Platform {
/// The name of the remote to connect to.
/// The name of the remote to connect to, or the URL of the remote to connect to directly.
///
/// If unset, the current branch will determine the 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>,

/// Output additional typically information provided by the server as part of the connection handshake.
#[clap(long)]
pub handshake_info: bool,
Expand Down

0 comments on commit 92bbe33

Please sign in to comment.