From 3378b4f728a4bad6f07a00bdbf947a600fc61ebb Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Thu, 5 Sep 2024 09:03:15 -0400 Subject: [PATCH] scalar: add --no-tags option to 'scalar clone' Some large repositories use tags to track a huge list of release versions. While this choice is costly on the ref advertisement, it is further wasteful for clients who do not need those tags. Allow clients to optionally skip the tag advertisement. This behavior is similar to that of 'git clone --no-tags' implemented in 0dab2468ee5 (clone: add a --no-tags option to clone without tags, 2017-04-26), including the modification of the remote.origin.tagOpt config value to include "--no-tags". One thing that is opposite of the 'git clone' implementation is that this allows '--tags' as an assumed option, which can be naturally negated with '--no-tags'. The clone command does not accept '--tags' but allows "--no-no-tags" as the negation of its '--no-tags' option. While testing this option, combine the test with the previously untested '--no-src' option introduced in 4527db8ff8c (scalar: add --[no-]src option, 2023-08-28). Signed-off-by: Derrick Stolee --- Documentation/scalar.txt | 7 +++++++ scalar.c | 15 ++++++++++++--- t/t9210-scalar.sh | 18 ++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/Documentation/scalar.txt b/Documentation/scalar.txt index 361f51a64736fa..7e4259c6743f9b 100644 --- a/Documentation/scalar.txt +++ b/Documentation/scalar.txt @@ -86,6 +86,13 @@ cloning. If the HEAD at the remote did not point at any branch when `/src` directory. Use `--no-src` to place the cloned repository directly in the `` directory. +--[no-]tags:: + By default, `scalar clone` will fetch the tag objects advertised by + the remote and future `git fetch` commands will do the same. Use + `--no-tags` to avoid fetching tags in `scalar clone` and to configure + the repository to avoid fetching tags in the future. To fetch tags after + cloning with `--no-tags`, run `git fetch --tags`. + --[no-]full-clone:: A sparse-checkout is initialized by default. This behavior can be turned off via `--full-clone`. diff --git a/scalar.c b/scalar.c index 6166a8dd4c8d1f..09560aeab5418b 100644 --- a/scalar.c +++ b/scalar.c @@ -410,7 +410,7 @@ static int cmd_clone(int argc, const char **argv) { const char *branch = NULL; int full_clone = 0, single_branch = 0, show_progress = isatty(2); - int src = 1; + int src = 1, tags = 1; struct option clone_options[] = { OPT_STRING('b', "branch", &branch, N_(""), N_("branch to checkout after clone")), @@ -421,11 +421,13 @@ static int cmd_clone(int argc, const char **argv) "be checked out")), OPT_BOOL(0, "src", &src, N_("create repository within 'src' directory")), + OPT_BOOL(0, "tags", &tags, + N_("specify if tags should be fetched during clone")), OPT_END(), }; const char * const clone_usage[] = { N_("scalar clone [--single-branch] [--branch ] [--full-clone]\n" - "\t[--[no-]src] []"), + "\t[--[no-]src] [--[no-]tags] []"), NULL }; const char *url; @@ -504,6 +506,11 @@ static int cmd_clone(int argc, const char **argv) goto cleanup; } + if (!tags && set_config("remote.origin.tagOpt=--no-tags")) { + res = error(_("could not disable tags in '%s'"), dir); + goto cleanup; + } + if (!full_clone && (res = run_git("sparse-checkout", "init", "--cone", NULL))) goto cleanup; @@ -513,7 +520,9 @@ static int cmd_clone(int argc, const char **argv) if ((res = run_git("fetch", "--quiet", show_progress ? "--progress" : "--no-progress", - "origin", NULL))) { + "origin", + (tags ? NULL : "--no-tags"), + NULL))) { warning(_("partial clone failed; attempting full clone")); if (set_config("remote.origin.promisor") || diff --git a/t/t9210-scalar.sh b/t/t9210-scalar.sh index a41b4fcc0859db..e8613990e13705 100755 --- a/t/t9210-scalar.sh +++ b/t/t9210-scalar.sh @@ -169,6 +169,24 @@ test_expect_success 'scalar clone' ' ) ' +test_expect_success 'scalar clone --no-... opts' ' + # Note: redirect stderr always to avoid having a verbose test + # run result in a difference in the --[no-]progress option. + GIT_TRACE2_EVENT="$(pwd)/no-opt-trace" scalar clone \ + --no-tags --no-src \ + "file://$(pwd)" no-opts --single-branch 2>/dev/null && + + test_subcommand git fetch --quiet --no-progress \ + origin --no-tags tags && + test_line_count = 0 tags + ) +' + test_expect_success 'scalar reconfigure' ' git init one/src && scalar register one &&