ls-remote: introduce --branches and deprecate --heads

We call the tips of branches "heads", but this command calls the option to show only branches "--heads", which confuses the branches themselves and the tips of branches. Straighten the terminology by introducing "--branches" option that limits the output to branches, and deprecate "--heads" option used that way. We do not plan to remove "--heads" or "-h" yet; we may want to do so at Git 3.0, in which case, we may need to start advertising upcoming removal with an extra warning when they are used. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jun 4, 2024 at 15:01 UTC b773fb882231cd8fac4ce37ffb5a8b1d985f37ea
3 files changed +39 -12
Documentation/git-ls-remote.txt
+7 -5
@@ -9,7 +9,7 @@ git-ls-remote - List references in a remote repository
9 SYNOPSIS
10 --------
11 [verse]
12 -'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
12 +'git ls-remote' [--branches] [--tags] [--refs] [--upload-pack=<exec>]
13 [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
14 [--symref] [<repository> [<patterns>...]]
15
@@ -21,14 +21,16 @@ commit IDs.
21
22 OPTIONS
23 -------
24 --h::
25 ---heads::
24 +-b::
25 +--branches::
26 -t::
27 --tags::
28 - Limit to only refs/heads and refs/tags, respectively.
28 + Limit to only local branches and local tags, respectively.
29 These options are _not_ mutually exclusive; when given
30 both, references stored in refs/heads and refs/tags are
31 - displayed. Note that `git ls-remote -h` used without
31 + displayed. Note that `--heads` and `-h` are deprecated
32 + synonyms for `--branches` and `-b` and may be removed in
33 + the future. Also note that `git ls-remote -h` used without
34 anything else on the command line gives help, consistent
35 with other git subcommands.
36
builtin/ls-remote.c
+5 -2
@@ -9,7 +9,7 @@
9 #include "wildmatch.h"
10
11 static const char * const ls_remote_usage[] = {
12 - N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
12 + N_("git ls-remote [--branches] [--tags] [--refs] [--upload-pack=<exec>]\n"
13 " [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\n"
14 " [--symref] [<repository> [<patterns>...]]"),
15 NULL
@@ -68,7 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
68 N_("path of git-upload-pack on the remote host"),
69 PARSE_OPT_HIDDEN },
70 OPT_BIT('t', "tags", &flags, N_("limit to tags"), REF_TAGS),
71 - OPT_BIT('h', "heads", &flags, N_("limit to heads"), REF_BRANCHES),
71 + OPT_BIT('b', "branches", &flags, N_("limit to branches"), REF_BRANCHES),
72 + OPT_BIT_F('h', "heads", &flags,
73 + N_("deprecated synonym for --branches"), REF_BRANCHES,
74 + PARSE_OPT_HIDDEN),
75 OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
76 OPT_BOOL(0, "get-url", &get_url,
77 N_("take url.<base>.insteadOf into account")),
t/t5512-ls-remote.sh
+27 -5
@@ -47,6 +47,7 @@ test_expect_success setup '
47 git show-ref -d >refs &&
48 sed -e "s/ / /" refs >>expected.all &&
49
50 + grep refs/heads/ expected.all >expected.branches &&
51 git remote add self "$(pwd)/.git" &&
52 git remote add self2 "."
53 '
@@ -71,6 +72,27 @@ test_expect_success 'ls-remote self' '
72 test_cmp expected.all actual
73 '
74
75 +test_expect_success 'ls-remote --branches self' '
76 + git ls-remote --branches self >actual &&
77 + test_cmp expected.branches actual &&
78 + git ls-remote -b self >actual &&
79 + test_cmp expected.branches actual
80 +'
81 +
82 +test_expect_success 'ls-remote -h is deprecated w/o warning' '
83 + git ls-remote -h self >actual 2>warning &&
84 + test_cmp expected.branches actual &&
85 + test_grep ! deprecated warning
86 +'
87 +
88 +test_expect_success 'ls-remote --heads is deprecated and hidden w/o warning' '
89 + test_expect_code 129 git ls-remote -h >short-help &&
90 + test_grep ! -e --head short-help &&
91 + git ls-remote --heads self >actual 2>warning &&
92 + test_cmp expected.branches actual &&
93 + test_grep ! deprecated warning
94 +'
95 +
96 test_expect_success 'ls-remote --sort="version:refname" --tags self' '
97 generate_references \
98 refs/tags/mark \
@@ -275,7 +297,7 @@ test_expect_success 'ls-remote with filtered symref (refname)' '
297 test_cmp expect actual
298 '
299
278 -test_expect_success 'ls-remote with filtered symref (--heads)' '
300 +test_expect_success 'ls-remote with filtered symref (--branches)' '
301 git symbolic-ref refs/heads/foo refs/tags/mark &&
302 cat >expect.v2 <<-EOF &&
303 ref: refs/tags/mark refs/heads/foo
@@ -283,9 +305,9 @@ test_expect_success 'ls-remote with filtered symref (--heads)' '
305 $rev refs/heads/main
306 EOF
307 grep -v "^ref: refs/tags/" <expect.v2 >expect.v0 &&
286 - git -c protocol.version=0 ls-remote --symref --heads . >actual.v0 &&
308 + git -c protocol.version=0 ls-remote --symref --branches . >actual.v0 &&
309 test_cmp expect.v0 actual.v0 &&
288 - git -c protocol.version=2 ls-remote --symref --heads . >actual.v2 &&
310 + git -c protocol.version=2 ls-remote --symref --branches . >actual.v2 &&
311 test_cmp expect.v2 actual.v2
312 '
313
@@ -335,9 +357,9 @@ test_expect_success 'ls-remote patterns work with all protocol versions' '
357 test_expect_success 'ls-remote prefixes work with all protocol versions' '
358 git for-each-ref --format="%(objectname) %(refname)" \
359 refs/heads/ refs/tags/ >expect &&
338 - git -c protocol.version=0 ls-remote --heads --tags . >actual.v0 &&
360 + git -c protocol.version=0 ls-remote --branches --tags . >actual.v0 &&
361 test_cmp expect actual.v0 &&
340 - git -c protocol.version=2 ls-remote --heads --tags . >actual.v2 &&
362 + git -c protocol.version=2 ls-remote --branches --tags . >actual.v2 &&
363 test_cmp expect actual.v2
364 '
365