Skip to content

Commit bc26f76

Browse files
To1negitster
authored andcommitted
clone: make it possible to specify --tags
Option --no-tags was added in 0dab246 (clone: add a --no-tags option to clone without tags, 2017-04-26). At the time there was no need to support --tags as well, although there was some conversation about it[1]. To simplify the code and to prepare for future commits, invert the flag internally. Functionally there is no change, because the flag is default-enabled passing `--tags` has no effect, so there's no need to add tests for this. [1]: https://lore.kernel.org/git/CAGZ79kbHuMpiavJ90kQLEL_AR0BEyArcZoEWAjPPhOFacN16YQ@mail.gmail.com/ Signed-off-by: Toon Claes <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f420a6 commit bc26f76

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Documentation/git-clone.txt

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ git clone [--template=<template-directory>]
1313
[-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror]
1414
[-o <name>] [-b <name>] [-u <upload-pack>] [--reference <repository>]
1515
[--dissociate] [--separate-git-dir <git-dir>]
16-
[--depth <depth>] [--[no-]single-branch] [--no-tags]
16+
[--depth <depth>] [--[no-]single-branch] [--[no-]tags]
1717
[--recurse-submodules[=<pathspec>]] [--[no-]shallow-submodules]
1818
[--[no-]remote-submodules] [--jobs <n>] [--sparse] [--[no-]reject-shallow]
1919
[--filter=<filter-spec>] [--also-filter-submodules]] [--] <repository>
@@ -273,12 +273,15 @@ corresponding `--mirror` and `--no-tags` options instead.
273273
branch when `--single-branch` clone was made, no remote-tracking
274274
branch is created.
275275

276-
`--no-tags`::
277-
Don't clone any tags, and set
278-
`remote.<remote>.tagOpt=--no-tags` in the config, ensuring
279-
that future `git pull` and `git fetch` operations won't follow
280-
any tags. Subsequent explicit tag fetches will still work,
281-
(see linkgit:git-fetch[1]).
276+
`--[no-]tags`::
277+
Control whether or not tags will be cloned. When `--no-tags` is
278+
given, the option will be become permanent by setting the
279+
`remote.<remote>.tagOpt=--no-tags` configuration. This ensures that
280+
future `git pull` and `git fetch` won't follow any tags. Subsequent
281+
explicit tag fetches will still work (see linkgit:git-fetch[1]).
282+
283+
By default, tags are cloned and passing `--tags` is thus typically a
284+
no-op, unless it cancels out a previous `--no-tags`.
282285
+
283286
Can be used in conjunction with `--single-branch` to clone and
284287
maintain a branch with no references other than a single cloned

builtin/clone.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
static int option_no_checkout, option_bare, option_mirror, option_single_branch = -1;
6161
static int option_local = -1, option_no_hardlinks, option_shared;
62-
static int option_no_tags;
62+
static int option_tags = 1; /* default enabled */
6363
static int option_shallow_submodules;
6464
static int config_reject_shallow = -1; /* unspecified */
6565
static char *remote_name = NULL;
@@ -470,7 +470,7 @@ static struct ref *wanted_peer_refs(const struct ref *refs,
470470
get_fetch_map(refs, &refspec->items[i], &tail, 0);
471471
}
472472

473-
if (!option_mirror && !option_single_branch && !option_no_tags)
473+
if (!option_mirror && !option_single_branch && option_tags)
474474
get_fetch_map(refs, &tag_refspec, &tail, 0);
475475

476476
refspec_item_clear(&tag_refspec);
@@ -562,7 +562,7 @@ static void update_remote_refs(const struct ref *refs,
562562

563563
if (refs) {
564564
write_remote_refs(mapped_refs);
565-
if (option_single_branch && !option_no_tags)
565+
if (option_single_branch && option_tags)
566566
write_followtags(refs, msg);
567567
}
568568

@@ -964,8 +964,8 @@ int cmd_clone(int argc,
964964
N_("deepen history of shallow clone, excluding ref")),
965965
OPT_BOOL(0, "single-branch", &option_single_branch,
966966
N_("clone only one branch, HEAD or --branch")),
967-
OPT_BOOL(0, "no-tags", &option_no_tags,
968-
N_("don't clone any tags, and make later fetches not to follow them")),
967+
OPT_BOOL(0, "tags", &option_tags,
968+
N_("clone tags, and make later fetches not to follow them")),
969969
OPT_BOOL(0, "shallow-submodules", &option_shallow_submodules,
970970
N_("any cloned submodules will be shallow")),
971971
OPT_STRING(0, "separate-git-dir", &real_git_dir, N_("gitdir"),
@@ -1296,7 +1296,7 @@ int cmd_clone(int argc,
12961296
git_config_set(key.buf, repo);
12971297
strbuf_reset(&key);
12981298

1299-
if (option_no_tags) {
1299+
if (!option_tags) {
13001300
strbuf_addf(&key, "remote.%s.tagOpt", remote_name);
13011301
git_config_set(key.buf, "--no-tags");
13021302
strbuf_reset(&key);
@@ -1389,7 +1389,7 @@ int cmd_clone(int argc,
13891389
if (option_branch)
13901390
expand_ref_prefix(&transport_ls_refs_options.ref_prefixes,
13911391
option_branch);
1392-
if (!option_no_tags)
1392+
if (option_tags)
13931393
strvec_push(&transport_ls_refs_options.ref_prefixes,
13941394
"refs/tags/");
13951395

0 commit comments

Comments
 (0)