Skip to content

Commit 4720666

Browse files
committed
option to print server information about the connection (#450)
1 parent 098961f commit 4720666

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

git-protocol/src/fetch/handshake.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::fetch::Ref;
44

55
/// The result of the [`handshake()`][super::handshake()] function.
66
#[derive(Debug, Clone)]
7+
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
78
pub struct Outcome {
89
/// The protocol version the server responded with. It might have downgraded the desired version.
910
pub server_protocol_version: git_transport::Protocol,

git-transport/src/client/capabilities.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub enum Error {
2424

2525
/// A structure to represent multiple [capabilities][Capability] or features supported by the server.
2626
#[derive(Debug, Clone)]
27+
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
2728
pub struct Capabilities {
2829
data: BString,
2930
value_sep: u8,

gitoxide-core/src/repository/remote.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod refs_impl {
1616

1717
pub enum Kind {
1818
Remote,
19-
Tracking { ref_specs: Vec<BString> },
19+
Tracking { ref_specs: Vec<BString>, server_info: bool },
2020
}
2121

2222
pub struct Context {
@@ -47,11 +47,13 @@ mod refs_impl {
4747
(None, Some(url)) => repo.remote_at(url)?,
4848
(Some(_), Some(_)) => bail!("Must not set both the remote name and the url - they are mutually exclusive"),
4949
};
50-
if let refs::Kind::Tracking { ref_specs } = &kind {
50+
if let refs::Kind::Tracking { ref_specs, .. } = &kind {
5151
if format != OutputFormat::Human {
5252
bail!("JSON output isn't yet supported for listing ref-mappings.");
5353
}
54-
remote.replace_refspecs(ref_specs.iter(), git::remote::Direction::Fetch)?;
54+
if !ref_specs.is_empty() {
55+
remote.replace_refspecs(ref_specs.iter(), git::remote::Direction::Fetch)?;
56+
}
5557
}
5658
progress.info(format!(
5759
"Connecting to {:?}",
@@ -67,9 +69,14 @@ mod refs_impl {
6769
.await?;
6870

6971
match kind {
70-
refs::Kind::Tracking { .. } => {
71-
print_refmap(&repo, remote.refspecs(git::remote::Direction::Fetch), map, out, err)
72-
}
72+
refs::Kind::Tracking { server_info, .. } => print_refmap(
73+
&repo,
74+
remote.refspecs(git::remote::Direction::Fetch),
75+
map,
76+
server_info,
77+
out,
78+
err,
79+
),
7380
refs::Kind::Remote => {
7481
match format {
7582
OutputFormat::Human => drop(print(out, &map.remote_refs)),
@@ -88,6 +95,7 @@ mod refs_impl {
8895
repo: &git::Repository,
8996
refspecs: &[RefSpec],
9097
mut map: git::remote::fetch::RefMap<'_>,
98+
server_info: bool,
9199
mut out: impl std::io::Write,
92100
mut err: impl std::io::Write,
93101
) -> anyhow::Result<()> {
@@ -150,6 +158,10 @@ mod refs_impl {
150158
}
151159
}
152160
}
161+
if server_info {
162+
writeln!(out, "Additional Information")?;
163+
writeln!(out, "{:?}", map.handshake)?;
164+
}
153165
Ok(())
154166
}
155167

src/plumbing/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,13 @@ pub fn main() -> Result<()> {
125125
remote::Subcommands::Refs | remote::Subcommands::RefMap { .. } => {
126126
let kind = match cmd {
127127
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
128-
remote::Subcommands::RefMap { ref_spec } => {
129-
core::repository::remote::refs::Kind::Tracking { ref_specs: ref_spec }
130-
}
128+
remote::Subcommands::RefMap {
129+
ref_spec,
130+
connection_info,
131+
} => core::repository::remote::refs::Kind::Tracking {
132+
ref_specs: ref_spec,
133+
server_info: connection_info,
134+
},
131135
};
132136
#[cfg(feature = "gitoxide-core-blocking-client")]
133137
{

src/plumbing/options.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ pub mod remote {
137137
/// Print all references available on the remote as filtered through ref-specs.
138138
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
139139
RefMap {
140+
/// Output additional typically internal information provided by the server.
141+
#[clap(long)]
142+
connection_info: bool,
140143
/// Override the built-in and configured ref-specs with one or more of the given ones.
141144
#[clap(parse(try_from_os_str = git::env::os_str_to_bstring))]
142145
ref_spec: Vec<git_repository::bstr::BString>,

0 commit comments

Comments
 (0)