Skip to content

Commit b773fb8

Browse files
committed
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 <[email protected]>
1 parent a096e70 commit b773fb8

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

Documentation/git-ls-remote.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-ls-remote - List references in a remote repository
99
SYNOPSIS
1010
--------
1111
[verse]
12-
'git ls-remote' [--heads] [--tags] [--refs] [--upload-pack=<exec>]
12+
'git ls-remote' [--branches] [--tags] [--refs] [--upload-pack=<exec>]
1313
[-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]
1414
[--symref] [<repository> [<patterns>...]]
1515

@@ -21,14 +21,16 @@ commit IDs.
2121

2222
OPTIONS
2323
-------
24-
-h::
25-
--heads::
24+
-b::
25+
--branches::
2626
-t::
2727
--tags::
28-
Limit to only refs/heads and refs/tags, respectively.
28+
Limit to only local branches and local tags, respectively.
2929
These options are _not_ mutually exclusive; when given
3030
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
3234
anything else on the command line gives help, consistent
3335
with other git subcommands.
3436

builtin/ls-remote.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "wildmatch.h"
1010

1111
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"
1313
" [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\n"
1414
" [--symref] [<repository> [<patterns>...]]"),
1515
NULL
@@ -68,7 +68,10 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
6868
N_("path of git-upload-pack on the remote host"),
6969
PARSE_OPT_HIDDEN },
7070
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),
7275
OPT_BIT(0, "refs", &flags, N_("do not show peeled tags"), REF_NORMAL),
7376
OPT_BOOL(0, "get-url", &get_url,
7477
N_("take url.<base>.insteadOf into account")),

t/t5512-ls-remote.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ test_expect_success setup '
4747
git show-ref -d >refs &&
4848
sed -e "s/ / /" refs >>expected.all &&
4949
50+
grep refs/heads/ expected.all >expected.branches &&
5051
git remote add self "$(pwd)/.git" &&
5152
git remote add self2 "."
5253
'
@@ -71,6 +72,27 @@ test_expect_success 'ls-remote self' '
7172
test_cmp expected.all actual
7273
'
7374

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+
7496
test_expect_success 'ls-remote --sort="version:refname" --tags self' '
7597
generate_references \
7698
refs/tags/mark \
@@ -275,17 +297,17 @@ test_expect_success 'ls-remote with filtered symref (refname)' '
275297
test_cmp expect actual
276298
'
277299

278-
test_expect_success 'ls-remote with filtered symref (--heads)' '
300+
test_expect_success 'ls-remote with filtered symref (--branches)' '
279301
git symbolic-ref refs/heads/foo refs/tags/mark &&
280302
cat >expect.v2 <<-EOF &&
281303
ref: refs/tags/mark refs/heads/foo
282304
$rev refs/heads/foo
283305
$rev refs/heads/main
284306
EOF
285307
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 &&
287309
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 &&
289311
test_cmp expect.v2 actual.v2
290312
'
291313

@@ -335,9 +357,9 @@ test_expect_success 'ls-remote patterns work with all protocol versions' '
335357
test_expect_success 'ls-remote prefixes work with all protocol versions' '
336358
git for-each-ref --format="%(objectname) %(refname)" \
337359
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 &&
339361
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 &&
341363
test_cmp expect actual.v2
342364
'
343365

0 commit comments

Comments
 (0)