Skip to content

Commit

Permalink
'remote' with its own sub-commands (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jan 1, 2022
1 parent db0251e commit 8677f7e
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 112 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
* [ ] support for thin packs (as needed for fetch/pull)
* **commitgraph**
* [x] **verify** - assure that a commitgraph is consistent
* [remote-ref-list](https://asciinema.org/a/359320)
* [x] list all (or given) references from a remote at the given URL
* **remote**
* [ref-list](https://asciinema.org/a/359320) - list all (or given) references from a remote at the given URL

[skim]: https://github.com/lotabout/skim
[git-hours]: https://github.com/kimmobrunfeldt/git-hours/blob/8aaeee237cb9d9028e7a2592a25ad8468b1f45e4/index.js#L114-L143
Expand Down
62 changes: 34 additions & 28 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use clap::Parser;
use gitoxide_core as core;
use gitoxide_core::pack::verify;

#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
use crate::plumbing::options::remote;
use crate::{
plumbing::options::{commitgraph, Args, Subcommands},
shared::pretty::prepare_and_run,
Expand Down Expand Up @@ -174,41 +176,45 @@ pub fn main() -> Result<()> {
},
),
#[cfg(feature = "gitoxide-core-async-client")]
Subcommands::RemoteRefList { protocol, url } => {
let (_handle, progress) =
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
let fut = core::remote::refs::list(
protocol,
&url,
git_features::progress::DoOrDiscard::from(progress),
core::remote::refs::Context {
thread_limit,
format,
out: std::io::stdout(),
},
);
return futures_lite::future::block_on(fut);
}
#[cfg(feature = "gitoxide-core-blocking-client")]
Subcommands::RemoteRefList { protocol, url } => prepare_and_run(
"remote-ref-list",
verbose,
progress,
progress_keep_open,
core::remote::refs::PROGRESS_RANGE,
move |progress, out, _err| {
core::remote::refs::list(
Subcommands::Remote(subcommands) => match subcommands {
remote::Subcommands::RefList { protocol, url } => {
let (_handle, progress) =
async_util::prepare(verbose, "remote-ref-list", Some(core::remote::refs::PROGRESS_RANGE));
let fut = core::remote::refs::list(
protocol,
&url,
git_features::progress::DoOrDiscard::from(progress),
core::remote::refs::Context {
thread_limit,
format,
out,
out: std::io::stdout(),
},
)
},
),
);
return futures_lite::future::block_on(fut);
}
},
#[cfg(feature = "gitoxide-core-blocking-client")]
Subcommands::Remote(subcommands) => match subcommands {
remote::Subcommands::RefList { protocol, url } => prepare_and_run(
"remote-ref-list",
verbose,
progress,
progress_keep_open,
core::remote::refs::PROGRESS_RANGE,
move |progress, out, _err| {
core::remote::refs::list(
protocol,
&url,
git_features::progress::DoOrDiscard::from(progress),
core::remote::refs::Context {
thread_limit,
format,
out,
},
)
},
),
},
Subcommands::PackIndexFromData {
iteration_mode,
pack_path,
Expand Down
45 changes: 30 additions & 15 deletions src/plumbing/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,10 @@ pub enum Subcommands {
/// If unset, they will be discarded.
directory: Option<PathBuf>,
},
/// List remote references from a remote identified by a url.
///
/// This is the plumbing equivalent of `git ls-remote`.
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
#[clap(setting = AppSettings::DisableVersionFlag)]
/// Subcommands for interacting with git remotes, e.g. git repositories hosted on servers.
#[clap(subcommand)]
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
RemoteRefList {
/// The protocol version to use. Valid values are 1 and 2
#[clap(long, short = 'p')]
protocol: Option<core::net::Protocol>,

/// the URLs or path from which to receive references
///
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
url: String,
},
Remote(remote::Subcommands),
#[clap(setting = AppSettings::DisableVersionFlag)]
PackIndexFromData {
/// Specify how to iterate the pack, defaults to 'verify'
Expand Down Expand Up @@ -262,6 +250,7 @@ pub mod commitgraph {

#[derive(Debug, clap::Parser)]
pub enum Subcommands {
/// Verify the integrity of a commit graph
#[clap(setting = AppSettings::DisableVersionFlag)]
Verify {
/// The path to '.git/objects/info/', '.git/objects/info/commit-graphs/', or '.git/objects/info/commit-graph' to validate.
Expand All @@ -273,3 +262,29 @@ pub mod commitgraph {
},
}
}

///
#[cfg(any(feature = "gitoxide-core-async-client", feature = "gitoxide-core-blocking-client"))]
pub mod remote {
use clap::AppSettings;
use gitoxide_core as core;

#[derive(Debug, clap::Parser)]
pub enum Subcommands {
/// List remote references from a remote identified by a url.
///
/// This is the plumbing equivalent of `git ls-remote`.
/// Supported URLs are documented here: <https://www.git-scm.com/docs/git-clone#_git_urls>
#[clap(setting = AppSettings::DisableVersionFlag)]
RefList {
/// The protocol version to use. Valid values are 1 and 2
#[clap(long, short = 'p')]
protocol: Option<core::net::Protocol>,

/// the URLs or path from which to receive references
///
/// See here for a list of supported URLs: <https://www.git-scm.com/docs/git-clone#_git_urls>
url: String,
},
}
}
126 changes: 65 additions & 61 deletions tests/journey/gix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,82 +193,86 @@ title "gix pack-receive"
)
)

title "gix remote-ref-list"
(when "running 'remote-ref-list'"
snapshot="$snapshot/remote-ref-list"
(small-repo-in-sandbox
if [[ "$kind" != "small" ]]; then
title "gix remote"
(when "running 'remote'"
snapshot="$snapshot/remote"
title "gix remote ref-list"
(with "the 'ref-list' subcommand"
snapshot="$snapshot/ref-list"
(small-repo-in-sandbox
if [[ "$kind" != "small" ]]; then

if [[ "$kind" != "async" ]]; then
(with "file:// protocol"
(with "version 1"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 .git
}
)
(with "version 2"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list --protocol 2 "$PWD/.git"
}
)
if test "$kind" = "max"; then
(with "--format json"
it "generates the correct output in JSON format" && {
WITH_SNAPSHOT="$snapshot/file-v-any-json" \
expect_run $SUCCESSFULLY "$exe_plumbing" --format json remote-ref-list .git
}
if [[ "$kind" != "async" ]]; then
(with "file:// protocol"
(with "version 1"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 .git
}
)
(with "version 2"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list --protocol 2 "$PWD/.git"
}
)
if test "$kind" = "max"; then
(with "--format json"
it "generates the correct output in JSON format" && {
WITH_SNAPSHOT="$snapshot/file-v-any-json" \
expect_run $SUCCESSFULLY "$exe_plumbing" --format json remote ref-list .git
}
)
fi
)
fi
)
fi

(with "git:// protocol"
launch-git-daemon
(with "version 1"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 git://localhost/
}
)
(with "version 2"
it "generates the correct output" && {
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 2 git://localhost/
}
)
)
if [[ "$kind" == "small" ]]; then
(with "https:// protocol (in small builds)"
it "fails as http is not compiled in" && {
WITH_SNAPSHOT="$snapshot/fail-http-in-small" \
expect_run $WITH_FAILURE "$exe_plumbing" remote-ref-list -p 1 https://github.com/byron/gitoxide
}
)
fi
(on_ci
if [[ "$kind" = "max" ]]; then
(with "https:// protocol"
(with "git:// protocol"
launch-git-daemon
(with "version 1"
it "generates the correct output" && {
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 1 https://github.com/byron/gitoxide
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 git://localhost/
}
)
(with "version 2"
it "generates the correct output" && {
expect_run $SUCCESSFULLY "$exe_plumbing" remote-ref-list -p 2 https://github.com/byron/gitoxide
WITH_SNAPSHOT="$snapshot/file-v-any" \
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 2 git://localhost/
}
)
)
if [[ "$kind" == "small" ]]; then
(with "https:// protocol (in small builds)"
it "fails as http is not compiled in" && {
WITH_SNAPSHOT="$snapshot/fail-http-in-small" \
expect_run $WITH_FAILURE "$exe_plumbing" remote ref-list -p 1 https://github.com/byron/gitoxide
}
)
fi
(on_ci
if [[ "$kind" = "max" ]]; then
(with "https:// protocol"
(with "version 1"
it "generates the correct output" && {
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 1 https://github.com/byron/gitoxide
}
)
(with "version 2"
it "generates the correct output" && {
expect_run $SUCCESSFULLY "$exe_plumbing" remote ref-list -p 2 https://github.com/byron/gitoxide
}
)
)
fi
)
else
it "fails as the CLI doesn't include networking in 'small' mode" && {
WITH_SNAPSHOT="$snapshot/remote ref-list-no-networking-in-small-failure" \
expect_run 2 "$exe_plumbing" remote ref-list -p 1 .git
}
fi
)
else
it "fails as the CLI doesn't include networking in 'small' mode" && {
WITH_SNAPSHOT="$snapshot/remote-ref-list-no-networking-in-small-failure" \
expect_run 2 "$exe_plumbing" remote-ref-list -p 1 .git
}
fi
)
)

Expand Down

This file was deleted.

0 comments on commit 8677f7e

Please sign in to comment.