Skip to content

Commit

Permalink
Correct printing of tag information (even though it doesn't look grea…
Browse files Browse the repository at this point in the history
…t) (#450)
  • Loading branch information
Byron committed Sep 18, 2022
1 parent d8f1608 commit f4d8198
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
27 changes: 17 additions & 10 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ mod refs_impl {

pub mod refs {
use crate::OutputFormat;
use git_repository::bstr::BString;

pub const PROGRESS_RANGE: std::ops::RangeInclusive<u8> = 1..=2;

pub enum Kind {
Remote,
Tracking,
Tracking { ref_specs: Vec<BString> },
}

pub struct Context {
Expand All @@ -33,11 +34,8 @@ mod refs_impl {
out: impl std::io::Write,
refs::Context { format, name, url }: refs::Context,
) -> anyhow::Result<()> {
if matches!(kind, refs::Kind::Tracking) && format != OutputFormat::Human {
bail!("JSON output isn't yet supported for listing ref-mappings.");
}
use anyhow::Context;
let remote = match (name, url) {
let mut remote = match (name, url) {
(Some(name), None) => repo.find_remote(&name)?,
(None, None) => repo
.head()?
Expand All @@ -46,6 +44,12 @@ mod refs_impl {
(None, Some(url)) => repo.remote_at(url)?,
(Some(_), Some(_)) => bail!("Must not set both the remote name and the url - they are mutually exclusive"),
};
if let refs::Kind::Tracking { ref_specs } = &kind {
if format != OutputFormat::Human {
bail!("JSON output isn't yet supported for listing ref-mappings.");
}
remote.replace_refspecs(ref_specs.iter(), git::remote::Direction::Fetch)?;
}
progress.info(format!(
"Connecting to {:?}",
remote
Expand All @@ -60,7 +64,7 @@ mod refs_impl {
.await?;

match kind {
refs::Kind::Tracking => print_refmap(&repo, remote, map, out),
refs::Kind::Tracking { .. } => print_refmap(&repo, remote, map, out),
refs::Kind::Remote => {
match format {
OutputFormat::Human => drop(print(out, &map.remote_refs)),
Expand Down Expand Up @@ -103,10 +107,13 @@ mod refs_impl {
Some(local) => {
write!(out, " -> {} ", local)?;
match repo.try_find_reference(local)? {
Some(mut tracking) => {
let msg = (tracking.peel_to_id_in_place()?.as_ref() == target_id)
.then(|| "[up-to-date]")
.unwrap_or("[changed]");
Some(tracking) => {
let msg = match tracking.try_id() {
Some(id) => (id.as_ref() == target_id)
.then(|| "[up-to-date]")
.unwrap_or("[changed]"),
None => "[skipped]",
};
writeln!(out, "{msg}")
}
None => writeln!(out, "[new]"),
Expand Down
6 changes: 4 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ pub fn main() -> Result<()> {
#[cfg_attr(feature = "small", allow(unused_variables))]
Subcommands::Remote(remote::Platform { name, url, cmd }) => match cmd {
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
remote::Subcommands::Refs | remote::Subcommands::RefMap => {
remote::Subcommands::Refs | remote::Subcommands::RefMap { .. } => {
let kind = match cmd {
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
remote::Subcommands::RefMap => core::repository::remote::refs::Kind::Tracking,
remote::Subcommands::RefMap { ref_spec } => {
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
}
};
#[cfg(feature = "gitoxide-core-blocking-client")]
{
Expand Down
7 changes: 6 additions & 1 deletion src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub mod config {

pub mod remote {
use git_repository as git;
use git_repository::bstr::BString;

#[derive(Debug, clap::Parser)]
pub struct Platform {
Expand All @@ -136,7 +137,11 @@ pub mod remote {
Refs,
/// Print all references available on the remote as filtered through ref-specs.
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
RefMap,
RefMap {
/// 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))]
ref_spec: Vec<BString>,
},
}
}

Expand Down

0 comments on commit f4d8198

Please sign in to comment.