Skip to content

Commit

Permalink
option to print server information about the connection (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 18, 2022
1 parent 098961f commit 4720666
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
1 change: 1 addition & 0 deletions git-protocol/src/fetch/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::fetch::Ref;

/// The result of the [`handshake()`][super::handshake()] function.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Outcome {
/// The protocol version the server responded with. It might have downgraded the desired version.
pub server_protocol_version: git_transport::Protocol,
Expand Down
1 change: 1 addition & 0 deletions git-transport/src/client/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum Error {

/// A structure to represent multiple [capabilities][Capability] or features supported by the server.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub struct Capabilities {
data: BString,
value_sep: u8,
Expand Down
24 changes: 18 additions & 6 deletions gitoxide-core/src/repository/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod refs_impl {

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

pub struct Context {
Expand Down Expand Up @@ -47,11 +47,13 @@ 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 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)?;
if !ref_specs.is_empty() {
remote.replace_refspecs(ref_specs.iter(), git::remote::Direction::Fetch)?;
}
}
progress.info(format!(
"Connecting to {:?}",
Expand All @@ -67,9 +69,14 @@ mod refs_impl {
.await?;

match kind {
refs::Kind::Tracking { .. } => {
print_refmap(&repo, remote.refspecs(git::remote::Direction::Fetch), map, out, err)
}
refs::Kind::Tracking { server_info, .. } => print_refmap(
&repo,
remote.refspecs(git::remote::Direction::Fetch),
map,
server_info,
out,
err,
),
refs::Kind::Remote => {
match format {
OutputFormat::Human => drop(print(out, &map.remote_refs)),
Expand All @@ -88,6 +95,7 @@ mod refs_impl {
repo: &git::Repository,
refspecs: &[RefSpec],
mut map: git::remote::fetch::RefMap<'_>,
server_info: bool,
mut out: impl std::io::Write,
mut err: impl std::io::Write,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -150,6 +158,10 @@ mod refs_impl {
}
}
}
if server_info {
writeln!(out, "Additional Information")?;
writeln!(out, "{:?}", map.handshake)?;
}
Ok(())
}

Expand Down
10 changes: 7 additions & 3 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,13 @@ pub fn main() -> Result<()> {
remote::Subcommands::Refs | remote::Subcommands::RefMap { .. } => {
let kind = match cmd {
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
remote::Subcommands::RefMap { ref_spec } => {
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
}
remote::Subcommands::RefMap {
ref_spec,
connection_info,
} => core::repository::remote::refs::Kind::Tracking {
ref_specs: ref_spec,
server_info: connection_info,
},
};
#[cfg(feature = "gitoxide-core-blocking-client")]
{
Expand Down
3 changes: 3 additions & 0 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ pub mod remote {
/// 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 {
/// Output additional typically internal information provided by the server.
#[clap(long)]
connection_info: bool,
/// 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<git_repository::bstr::BString>,
Expand Down

0 comments on commit 4720666

Please sign in to comment.