Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8677f7e

Browse files
committed
'remote' with its own sub-commands (#289)
1 parent db0251e commit 8677f7e

7 files changed

Lines changed: 131 additions & 112 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
3939
* [ ] support for thin packs (as needed for fetch/pull)
4040
* **commitgraph**
4141
* [x] **verify** - assure that a commitgraph is consistent
42-
* [remote-ref-list](https://asciinema.org/a/359320)
43-
* [x] list all (or given) references from a remote at the given URL
42+
* **remote**
43+
* [ref-list](https://asciinema.org/a/359320) - list all (or given) references from a remote at the given URL
4444

4545
[skim]: https://github.com/lotabout/skim
4646
[git-hours]: https://github.com/kimmobrunfeldt/git-hours/blob/8aaeee237cb9d9028e7a2592a25ad8468b1f45e4/index.js#L114-L143

src/plumbing/main.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use clap::Parser;
1212
use gitoxide_core as core;
1313
use gitoxide_core::pack::verify;
1414

15+
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
16+
use crate::plumbing::options::remote;
1517
use crate::{
1618
plumbing::options::{commitgraph, Args, Subcommands},
1719
shared::pretty::prepare_and_run,
@@ -174,41 +176,45 @@ pub fn main() -> Result<()> {
174176
},
175177
),
176178
#[cfg(feature = "gitoxide-core-async-client")]
177-
Subcommands::RemoteRefList { protocol, url } => {
178-
let (_handle, progress) =
179-
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
180-
let fut = core::remote::refs::list(
181-
protocol,
182-
&url,
183-
git_features::progress::DoOrDiscard::from(progress),
184-
core::remote::refs::Context {
185-
thread_limit,
186-
format,
187-
out: std::io::stdout(),
188-
},
189-
);
190-
return futures_lite::future::block_on(fut);
191-
}
192-
#[cfg(feature = "gitoxide-core-blocking-client")]
193-
Subcommands::RemoteRefList { protocol, url } => prepare_and_run(
194-
"remote-ref-list",
195-
verbose,
196-
progress,
197-
progress_keep_open,
198-
core::remote::refs::PROGRESS_RANGE,
199-
move |progress, out, _err| {
200-
core::remote::refs::list(
179+
Subcommands::Remote(subcommands) => match subcommands {
180+
remote::Subcommands::RefList { protocol, url } => {
181+
let (_handle, progress) =
182+
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
183+
let fut = core::remote::refs::list(
201184
protocol,
202185
&url,
203186
git_features::progress::DoOrDiscard::from(progress),
204187
core::remote::refs::Context {
205188
thread_limit,
206189
format,
207-
out,
190+
out: std::io::stdout(),
208191
},
209-
)
210-
},
211-
),
192+
);
193+
return futures_lite::future::block_on(fut);
194+
}
195+
},
196+
#[cfg(feature = "gitoxide-core-blocking-client")]
197+
Subcommands::Remote(subcommands) => match subcommands {
198+
remote::Subcommands::RefList { protocol, url } => prepare_and_run(
199+
"remote-ref-list",
200+
verbose,
201+
progress,
202+
progress_keep_open,
203+
core::remote::refs::PROGRESS_RANGE,
204+
move |progress, out, _err| {
205+
core::remote::refs::list(
206+
protocol,
207+
&url,
208+
git_features::progress::DoOrDiscard::from(progress),
209+
core::remote::refs::Context {
210+
thread_limit,
211+
format,
212+
out,
213+
},
214+
)
215+
},
216+
),
217+
},
212218
Subcommands::PackIndexFromData {
213219
iteration_mode,
214220
pack_path,

src/plumbing/options.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,10 @@ pub enum Subcommands {
132132
/// If unset, they will be discarded.
133133
directory: Option<PathBuf>,
134134
},
135-
/// List remote references from a remote identified by a url.
136-
///
137-
/// This is the plumbing equivalent of `git ls-remote`.
138-
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
139-
#[clap(setting = AppSettings::DisableVersionFlag)]
135+
/// Subcommands for interacting with git remotes, e.g. git repositories hosted on servers.
136+
#[clap(subcommand)]
140137
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
141-
RemoteRefList {
142-
/// The protocol version to use. Valid values are 1 and 2
143-
#[clap(long, short = 'p')]
144-
protocol: Option<core::net::Protocol>,
145-
146-
/// the URLs or path from which to receive references
147-
///
148-
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
149-
url: String,
150-
},
138+
Remote(remote::Subcommands),
151139
#[clap(setting = AppSettings::DisableVersionFlag)]
152140
PackIndexFromData {
153141
/// Specify how to iterate the pack, defaults to 'verify'
@@ -262,6 +250,7 @@ pub mod commitgraph {
262250

263251
#[derive(Debug, clap::Parser)]
264252
pub enum Subcommands {
253+
/// Verify the integrity of a commit graph
265254
#[clap(setting = AppSettings::DisableVersionFlag)]
266255
Verify {
267256
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
@@ -273,3 +262,29 @@ pub mod commitgraph {
273262
},
274263
}
275264
}
265+
266+
///
267+
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
268+
pub mod remote {
269+
use clap::AppSettings;
270+
use gitoxide_core as core;
271+
272+
#[derive(Debug, clap::Parser)]
273+
pub enum Subcommands {
274+
/// List remote references from a remote identified by a url.
275+
///
276+
/// This is the plumbing equivalent of `git ls-remote`.
277+
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
278+
#[clap(setting = AppSettings::DisableVersionFlag)]
279+
RefList {
280+
/// The protocol version to use. Valid values are 1 and 2
281+
#[clap(long, short = 'p')]
282+
protocol: Option<core::net::Protocol>,
283+
284+
/// the URLs or path from which to receive references
285+
///
286+
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
287+
url: String,
288+
},
289+
}
290+
}

tests/journey/gix.sh

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -193,82 +193,86 @@ title "gix pack-receive"
193193
)
194194
)
195195

196-
title "gix remote-ref-list"
197-
(when "running 'remote-ref-list'"
198-
snapshot="$snapshot/remote-ref-list"
199-
(small-repo-in-sandbox
200-
if [[ "$kind" != "small" ]]; then
196+
title "gix remote"
197+
(when "running 'remote'"
198+
snapshot="$snapshot/remote"
199+
title "gix remote ref-list"
200+
(with "the 'ref-list' subcommand"
201+
snapshot="$snapshot/ref-list"
202+
(small-repo-in-sandbox
203+
if [[ "$kind" != "small" ]]; then
201204

202-
if [[ "$kind" != "async" ]]; then
203-
(with "file:// protocol"
204-
(with "version 1"
205-
it "generates the correct output" && {
206-
WITH_SNAPSHOT="$snapshot/file-v-any" \
207-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 .git
208-
}
209-
)
210-
(with "version 2"
211-
it "generates the correct output" && {
212-
WITH_SNAPSHOT="$snapshot/file-v-any" \
213-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list --protocol 2 "$PWD/.git"
214-
}
215-
)
216-
if test "$kind" = "max"; then
217-
(with "--format json"
218-
it "generates the correct output in JSON format" && {
219-
WITH_SNAPSHOT="$snapshot/file-v-any-json" \
220-
expect_run $SUCCESSFULLY "$exe_plumbing" --format json remote-ref-list .git
221-
}
205+
if [[ "$kind" != "async" ]]; then
206+
(with "file:// protocol"
207+
(with "version 1"
208+
it "generates the correct output" && {
209+
WITH_SNAPSHOT="$snapshot/file-v-any" \
210+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 .git
211+
}
212+
)
213+
(with "version 2"
214+
it "generates the correct output" && {
215+
WITH_SNAPSHOT="$snapshot/file-v-any" \
216+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list --protocol 2 "$PWD/.git"
217+
}
218+
)
219+
if test "$kind" = "max"; then
220+
(with "--format json"
221+
it "generates the correct output in JSON format" && {
222+
WITH_SNAPSHOT="$snapshot/file-v-any-json" \
223+
expect_run $SUCCESSFULLY "$exe_plumbing" --format json remote ref-list .git
224+
}
225+
)
226+
fi
222227
)
223228
fi
224-
)
225-
fi
226229

227-
(with "git:// protocol"
228-
launch-git-daemon
229-
(with "version 1"
230-
it "generates the correct output" && {
231-
WITH_SNAPSHOT="$snapshot/file-v-any" \
232-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 git://localhost/
233-
}
234-
)
235-
(with "version 2"
236-
it "generates the correct output" && {
237-
WITH_SNAPSHOT="$snapshot/file-v-any" \
238-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 2 git://localhost/
239-
}
240-
)
241-
)
242-
if [[ "$kind" == "small" ]]; then
243-
(with "https:// protocol (in small builds)"
244-
it "fails as http is not compiled in" && {
245-
WITH_SNAPSHOT="$snapshot/fail-http-in-small" \
246-
expect_run $WITH_FAILURE "$exe_plumbing" remote-ref-list -p 1 https://github.com/byron/gitoxide
247-
}
248-
)
249-
fi
250-
(on_ci
251-
if [[ "$kind" = "max" ]]; then
252-
(with "https:// protocol"
230+
(with "git:// protocol"
231+
launch-git-daemon
253232
(with "version 1"
254233
it "generates the correct output" && {
255-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 https://github.com/byron/gitoxide
234+
WITH_SNAPSHOT="$snapshot/file-v-any" \
235+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 git://localhost/
256236
}
257237
)
258238
(with "version 2"
259239
it "generates the correct output" && {
260-
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 2 https://github.com/byron/gitoxide
240+
WITH_SNAPSHOT="$snapshot/file-v-any" \
241+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 2 git://localhost/
261242
}
262243
)
263244
)
245+
if [[ "$kind" == "small" ]]; then
246+
(with "https:// protocol (in small builds)"
247+
it "fails as http is not compiled in" && {
248+
WITH_SNAPSHOT="$snapshot/fail-http-in-small" \
249+
expect_run $WITH_FAILURE "$exe_plumbing" remote ref-list -p 1 https://github.com/byron/gitoxide
250+
}
251+
)
252+
fi
253+
(on_ci
254+
if [[ "$kind" = "max" ]]; then
255+
(with "https:// protocol"
256+
(with "version 1"
257+
it "generates the correct output" && {
258+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 https://github.com/byron/gitoxide
259+
}
260+
)
261+
(with "version 2"
262+
it "generates the correct output" && {
263+
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 2 https://github.com/byron/gitoxide
264+
}
265+
)
266+
)
267+
fi
268+
)
269+
else
270+
it "fails as the CLI doesn't include networking in 'small' mode" && {
271+
WITH_SNAPSHOT="$snapshot/remote ref-list-no-networking-in-small-failure" \
272+
expect_run 2 "$exe_plumbing" remote ref-list -p 1 .git
273+
}
264274
fi
265275
)
266-
else
267-
it "fails as the CLI doesn't include networking in 'small' mode" && {
268-
WITH_SNAPSHOT="$snapshot/remote-ref-list-no-networking-in-small-failure" \
269-
expect_run 2 "$exe_plumbing" remote-ref-list -p 1 .git
270-
}
271-
fi
272276
)
273277
)
274278

tests/snapshots/plumbing/remote-ref-list/remote-ref-list-no-networking-in-small-failure

Lines changed: 0 additions & 6 deletions
This file was deleted.
File renamed without changes.

tests/snapshots/plumbing/remote-ref-list/file-v-any-json renamed to tests/snapshots/plumbing/remote/ref-list/file-v-any-json

File renamed without changes.

0 commit comments

Comments
 (0)