From 46a3511aead043bc45256ce603285ff4d0fff60a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 11 Sep 2020 17:37:57 +0800 Subject: [PATCH] [clone] first journey test for pack-receive --- src/plumbing/lean/options.rs | 2 +- src/plumbing/pretty/main.rs | 24 +++++++ src/plumbing/pretty/options.rs | 17 +++++ .../plumbing/pack-receive/file-v-any | 1 + tests/stateless-journey.sh | 65 ++++++++++++------- 5 files changed, 85 insertions(+), 24 deletions(-) create mode 100644 tests/snapshots/plumbing/pack-receive/file-v-any diff --git a/src/plumbing/lean/options.rs b/src/plumbing/lean/options.rs index 33847034e91..1fc363cf7a6 100644 --- a/src/plumbing/lean/options.rs +++ b/src/plumbing/lean/options.rs @@ -89,7 +89,7 @@ pub struct RemoteRefList { #[argh(subcommand, name = "pack-receive")] pub struct PackReceive { /// the protocol version to use. Valid values are 1 and 2 - #[argh(option)] + #[argh(option, short = 'p')] pub protocol: Option, /// the URLs or path from which to receive the pack. diff --git a/src/plumbing/pretty/main.rs b/src/plumbing/pretty/main.rs index ed973c66e35..53d5d33e891 100644 --- a/src/plumbing/pretty/main.rs +++ b/src/plumbing/pretty/main.rs @@ -125,6 +125,30 @@ pub fn main() -> Result<()> { git_features::interrupt::init_handler(std::io::stderr()); match cmd { + Subcommands::PackReceive { + protocol, + url, + directory, + } => prepare_and_run( + "pack-receive", + verbose, + progress, + progress_keep_open, + core::pack::receive::PROGRESS_RANGE, + move |progress, out, _err| { + core::pack::receive( + protocol, + &url, + directory, + git_features::progress::DoOrDiscard::from(progress), + core::pack::receive::Context { + thread_limit, + format, + out, + }, + ) + }, + ), Subcommands::RemoteRefList { protocol, url } => prepare_and_run( "remote-ref-list", verbose, diff --git a/src/plumbing/pretty/options.rs b/src/plumbing/pretty/options.rs index 84f57d82a03..5b7e757d588 100644 --- a/src/plumbing/pretty/options.rs +++ b/src/plumbing/pretty/options.rs @@ -42,6 +42,23 @@ pub struct Args { #[derive(Debug, Clap)] pub enum Subcommands { + #[clap(setting = AppSettings::ColoredHelp)] + #[clap(setting = AppSettings::DisableVersion)] + PackReceive { + /// The protocol version to use. Valid values are 1 and 2 + #[clap(long, short = "p")] + protocol: Option, + + /// The URLs or path from which to receive the pack. + /// + /// See here for a list of supported URLs: https://www.git-scm.com/docs/git-clone#_git_urls + url: String, + + /// The directory into which to write the received pack and index. + /// + /// If unset, they will be discarded. + directory: Option, + }, /// List remote references from a remote identified by a url. /// /// This is the plumbing equivalent of `git ls-remote`. diff --git a/tests/snapshots/plumbing/pack-receive/file-v-any b/tests/snapshots/plumbing/pack-receive/file-v-any new file mode 100644 index 00000000000..658dc01e532 --- /dev/null +++ b/tests/snapshots/plumbing/pack-receive/file-v-any @@ -0,0 +1 @@ +Outcome { index: Outcome { index_kind: V2, index_hash: Id([199, 135, 222, 42, 175, 184, 151, 65, 124, 168, 22, 123, 174, 177, 70, 234, 189, 24, 188, 95]), data_hash: Id([52, 101, 116, 183, 51, 29, 195, 161, 114, 77, 162, 24, 214, 34, 198, 225, 182, 198, 106, 87]), num_objects: 9 }, pack_kind: V2, index_path: None, data_path: None } \ No newline at end of file diff --git a/tests/stateless-journey.sh b/tests/stateless-journey.sh index 497b2577fa4..99204377e57 100755 --- a/tests/stateless-journey.sh +++ b/tests/stateless-journey.sh @@ -48,33 +48,52 @@ title "CLI ${kind}" ) ) +function small-repo-in-sandbox() { + sandbox + { + git init + git config commit.gpgsign false + set -a + export GIT_AUTHOR_DATE="2020-09-09 09:06:03 +0800" + export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" + export GIT_AUTHOR_NAME="Sebastian Thiel" + export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}" + export GIT_AUTHOR_EMAIL="git@example.com" + export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}" + touch a + git add a + git commit -m "first" + git tag unannotated + touch b + git add b + git commit -m "second" + git tag annotated -m "tag message" + git branch dev + echo hi >> b + git commit -am "third" + } &>/dev/null +} + title plumbing snapshot="$snapshot/plumbing" +(when "running 'pack-receive'" + snapshot="$snapshot/pack-receive" + (small-repo-in-sandbox + (with "file:// protocol" + (with "version 1" + (with "no output directory" + it "generates the correct output" && { + WITH_SNAPSHOT="$snapshot/file-v-any" \ + expect_run $SUCCESSFULLY "$exe_plumbing" pack-receive -p 1 .git + } + ) + ) + ) + ) +) (when "running 'remote-ref-list'" snapshot="$snapshot/remote-ref-list" - (sandbox - { - git init - git config commit.gpgsign false - set -a - export GIT_AUTHOR_DATE="2020-09-09 09:06:03 +0800" - export GIT_COMMITTER_DATE="${GIT_AUTHOR_DATE}" - export GIT_AUTHOR_NAME="Sebastian Thiel" - export GIT_COMMITTER_NAME="${GIT_AUTHOR_NAME}" - export GIT_AUTHOR_EMAIL="git@example.com" - export GIT_COMMITTER_EMAIL="${GIT_AUTHOR_EMAIL}" - touch a - git add a - git commit -m "first" - git tag unannotated - touch b - git add b - git commit -m "second" - git tag annotated -m "tag message" - git branch dev - echo hi >> b - git commit -am "third" - } &>/dev/null + (small-repo-in-sandbox (with "file:// protocol" (with "version 1" it "generates the correct output" && {