Skip to content

Commit 94c2b78

Browse files
committed
wire up the ref-map sub-command. (#450)
Without implementation though, which is mainly display.
1 parent c9ff885 commit 94c2b78

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
4848
* [x] **previous-branches** - list all previously checked out branches, powered by the ref-log.
4949
* **remote**
5050
* [x] **refs** - list all references available on the remote based on the current remote configuration.
51+
* [x] **ref-map** - show how remote references relate to their local tracking branches as mapped by refspecs.
5152
* **credential**
5253
* [x] **fill/approve/reject** - The same as `git credential`, but implemented in Rust, calling helpers only when from trusted configuration.
5354
* **free** - no git repository necessary

Diff for: crate-status.md

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
### git-object
1515
* *decode (zero-copy)* borrowed objects
1616
* [x] commit
17-
* [x] parse the title, body, and provide a title summary.
1817
* [ ] parse [trailers](https://git-scm.com/docs/git-interpret-trailers#_description)
1918
* [x] tree
2019
* encode owned objects

Diff for: gitoxide-core/src/repository/remote.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
2-
mod net {
2+
mod refs_impl {
33
use anyhow::bail;
44
use git_repository as git;
55
use git_repository::protocol::fetch;
@@ -11,6 +11,11 @@ mod net {
1111

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

14+
pub enum Kind {
15+
Remote,
16+
Tracking,
17+
}
18+
1419
pub struct Context {
1520
pub format: OutputFormat,
1621
pub name: Option<String>,
@@ -23,6 +28,7 @@ mod net {
2328
#[git::protocol::maybe_async::maybe_async]
2429
pub async fn refs_fn(
2530
repo: git::Repository,
31+
_kind: refs::Kind,
2632
mut progress: impl git::Progress,
2733
out: impl std::io::Write,
2834
refs::Context { format, name, url }: refs::Context,
@@ -44,17 +50,17 @@ mod net {
4450
.context("Remote didn't have a URL to connect to")?
4551
.to_bstring()
4652
));
47-
let refs = remote
53+
let map = remote
4854
.connect(git::remote::Direction::Fetch, progress)
4955
.await?
50-
.list_refs()
56+
.ref_map()
5157
.await?;
5258

5359
match format {
54-
OutputFormat::Human => drop(print(out, &refs)),
60+
OutputFormat::Human => drop(print(out, &map.remote_refs)),
5561
#[cfg(feature = "serde1")]
5662
OutputFormat::Json => {
57-
serde_json::to_writer_pretty(out, &refs.into_iter().map(JsonRef::from).collect::<Vec<_>>())?
63+
serde_json::to_writer_pretty(out, &map.remote_refs.into_iter().map(JsonRef::from).collect::<Vec<_>>())?
5864
}
5965
};
6066
Ok(())
@@ -137,4 +143,4 @@ mod net {
137143
}
138144
}
139145
#[cfg(any(feature = "blocking-client", feature = "async-client"))]
140-
pub use net::{refs, refs_fn as refs, JsonRef};
146+
pub use refs_impl::{refs, refs_fn as refs, JsonRef};

Diff for: src/plumbing/main.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ pub fn main() -> Result<()> {
122122
#[cfg_attr(feature = "small", allow(unused_variables))]
123123
Subcommands::Remote(remote::Platform { name, url, cmd }) => match cmd {
124124
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
125-
remote::Subcommands::Refs => {
125+
remote::Subcommands::Refs | remote::Subcommands::RefMap => {
126+
let kind = match cmd {
127+
remote::Subcommands::Refs => core::repository::remote::refs::Kind::Remote,
128+
remote::Subcommands::RefMap => core::repository::remote::refs::Kind::Tracking,
129+
};
126130
#[cfg(feature = "gitoxide-core-blocking-client")]
127131
{
128132
prepare_and_run(
@@ -134,6 +138,7 @@ pub fn main() -> Result<()> {
134138
move |progress, out, _err| {
135139
core::repository::remote::refs(
136140
repository(Mode::LenientWithGitInstallConfig)?,
141+
kind,
137142
progress,
138143
out,
139144
core::repository::remote::refs::Context { name, url, format },
@@ -149,7 +154,8 @@ pub fn main() -> Result<()> {
149154
Some(core::repository::remote::refs::PROGRESS_RANGE),
150155
);
151156
futures_lite::future::block_on(core::repository::remote::refs(
152-
repository(Mode::Lenient)?,
157+
repository(Mode::LenientWithGitInstallConfig)?,
158+
kind,
153159
progress,
154160
std::io::stdout(),
155161
core::repository::remote::refs::Context { name, url, format },

Diff for: src/plumbing/options.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,12 @@ pub mod remote {
131131
#[derive(Debug, clap::Subcommand)]
132132
#[clap(visible_alias = "remotes")]
133133
pub enum Subcommands {
134-
/// Print all references available on the remote
134+
/// Print all references available on the remote.
135135
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
136136
Refs,
137+
/// Print all references available on the remote as filtered through ref-specs.
138+
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
139+
RefMap,
137140
}
138141
}
139142

0 commit comments

Comments
 (0)