Skip to content

Commit 892fd8b

Browse files
committed
Merge branch 'jc/heads-are-branches'
The "--heads" option of "ls-remote" and "show-ref" has been been deprecated; "--branches" replaces "--heads". * jc/heads-are-branches: show-ref: introduce --branches and deprecate --heads ls-remote: introduce --branches and deprecate --heads refs: call branches branches
2 parents 166cdd8 + 607c3d3 commit 892fd8b

File tree

8 files changed

+78
-39
lines changed

8 files changed

+78
-39
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

Documentation/git-show-ref.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ SYNOPSIS
99
--------
1010
[verse]
1111
'git show-ref' [--head] [-d | --dereference]
12-
[-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]
13-
[--heads] [--] [<pattern>...]
12+
[-s | --hash[=<n>]] [--abbrev[=<n>]] [--branches] [--tags]
13+
[--] [<pattern>...]
1414
'git show-ref' --verify [-q | --quiet] [-d | --dereference]
1515
[-s | --hash[=<n>]] [--abbrev[=<n>]]
1616
[--] [<ref>...]
@@ -45,12 +45,14 @@ OPTIONS
4545

4646
Show the HEAD reference, even if it would normally be filtered out.
4747

48-
--heads::
48+
--branches::
4949
--tags::
5050

51-
Limit to "refs/heads" and "refs/tags", respectively. These options
51+
Limit to local branches and local tags, respectively. These options
5252
are not mutually exclusive; when given both, references stored in
53-
"refs/heads" and "refs/tags" are displayed.
53+
"refs/heads" and "refs/tags" are displayed. Note that `--heads`
54+
is a deprecated synonym for `--branches` and may be removed
55+
in the future.
5456

5557
-d::
5658
--dereference::
@@ -139,7 +141,7 @@ When using `--hash` (and not `--dereference`), the output is in the format:
139141
For example,
140142

141143
-----------------------------------------------------------------------------
142-
$ git show-ref --heads --hash
144+
$ git show-ref --branches --hash
143145
2e3ba0114a1f52b47df29743d6915d056be13278
144146
185008ae97960c8d551adcd9e23565194651b5d1
145147
03adf42c988195b50e1a1935ba5fcbc39b2b029b
@@ -183,8 +185,8 @@ to check whether a particular branch exists or not (notice how we don't
183185
actually want to show any results, and we want to use the full refname for it
184186
in order to not trigger the problem with ambiguous partial matches).
185187

186-
To show only tags, or only proper branch heads, use `--tags` and/or `--heads`
187-
respectively (using both means that it shows tags and heads, but not other
188+
To show only tags, or only proper branch heads, use `--tags` and/or `--branches`
189+
respectively (using both means that it shows tags and branches, but not other
188190
random references under the refs/ subdirectory).
189191

190192
To do automatic tag object dereferencing, use the `-d` or `--dereference`

builtin/ls-remote.c

Lines changed: 6 additions & 3 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_HEADS),
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")),
@@ -100,7 +103,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
100103

101104
if (flags & REF_TAGS)
102105
strvec_push(&transport_options.ref_prefixes, "refs/tags/");
103-
if (flags & REF_HEADS)
106+
if (flags & REF_BRANCHES)
104107
strvec_push(&transport_options.ref_prefixes, "refs/heads/");
105108

106109
remote = remote_get(dest);

builtin/show-ref.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
static const char * const show_ref_usage[] = {
1313
N_("git show-ref [--head] [-d | --dereference]\n"
14-
" [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags]\n"
15-
" [--heads] [--] [<pattern>...]"),
14+
" [-s | --hash[=<n>]] [--abbrev[=<n>]] [--branches] [--tags]\n"
15+
" [--] [<pattern>...]"),
1616
N_("git show-ref --verify [-q | --quiet] [-d | --dereference]\n"
1717
" [-s | --hash[=<n>]] [--abbrev[=<n>]]\n"
1818
" [--] [<ref>...]"),
@@ -189,7 +189,7 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
189189

190190
struct patterns_options {
191191
int show_head;
192-
int heads_only;
192+
int branches_only;
193193
int tags_only;
194194
};
195195

@@ -208,8 +208,8 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
208208
if (opts->show_head)
209209
refs_head_ref(get_main_ref_store(the_repository), show_ref,
210210
&show_ref_data);
211-
if (opts->heads_only || opts->tags_only) {
212-
if (opts->heads_only)
211+
if (opts->branches_only || opts->tags_only) {
212+
if (opts->branches_only)
213213
refs_for_each_fullref_in(get_main_ref_store(the_repository),
214214
"refs/heads/", NULL,
215215
show_ref, &show_ref_data);
@@ -293,8 +293,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
293293
struct show_one_options show_one_opts = {0};
294294
int verify = 0, exists = 0;
295295
const struct option show_ref_options[] = {
296-
OPT_BOOL(0, "tags", &patterns_opts.tags_only, N_("only show tags (can be combined with heads)")),
297-
OPT_BOOL(0, "heads", &patterns_opts.heads_only, N_("only show heads (can be combined with tags)")),
296+
OPT_BOOL(0, "tags", &patterns_opts.tags_only, N_("only show tags (can be combined with branches)")),
297+
OPT_BOOL(0, "branches", &patterns_opts.branches_only, N_("only show branches (can be combined with tags)")),
298+
OPT_HIDDEN_BOOL(0, "heads", &patterns_opts.branches_only,
299+
N_("deprecated synonym for --branches")),
298300
OPT_BOOL(0, "exists", &exists, N_("check for reference existence without resolving")),
299301
OPT_BOOL(0, "verify", &verify, N_("stricter reference checking, "
300302
"requires exact ref path")),

connect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ static int check_ref(const char *name, unsigned int flags)
3838
REFNAME_ALLOW_ONELEVEL))
3939
return 0;
4040

41-
/* REF_HEADS means that we want regular branch heads */
42-
if ((flags & REF_HEADS) && starts_with(name, "heads/"))
41+
/* REF_BRANCHES means that we want regular branch heads */
42+
if ((flags & REF_BRANCHES) && starts_with(name, "heads/"))
4343
return 1;
4444

4545
/* REF_TAGS means that we want tags */

remote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct ref {
200200
};
201201

202202
#define REF_NORMAL (1u << 0)
203-
#define REF_HEADS (1u << 1)
203+
#define REF_BRANCHES (1u << 1)
204204
#define REF_TAGS (1u << 2)
205205

206206
struct ref *find_ref_by_name(const struct ref *list, const char *name);

t/t1403-show-ref.sh

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ test_expect_success 'show-ref -d' '
121121
122122
'
123123

124-
test_expect_success 'show-ref --heads, --tags, --head, pattern' '
124+
test_expect_success 'show-ref --branches, --tags, --head, pattern' '
125125
for branch in B main side
126126
do
127127
echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
128-
done >expect.heads &&
129-
git show-ref --heads >actual &&
130-
test_cmp expect.heads actual &&
128+
done >expect.branches &&
129+
git show-ref --branches >actual &&
130+
test_cmp expect.branches actual &&
131131
132132
for tag in A B C
133133
do
@@ -136,15 +136,15 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
136136
git show-ref --tags >actual &&
137137
test_cmp expect.tags actual &&
138138
139-
cat expect.heads expect.tags >expect &&
140-
git show-ref --heads --tags >actual &&
139+
cat expect.branches expect.tags >expect &&
140+
git show-ref --branches --tags >actual &&
141141
test_cmp expect actual &&
142142
143143
{
144144
echo $(git rev-parse HEAD) HEAD &&
145-
cat expect.heads expect.tags
145+
cat expect.branches expect.tags
146146
} >expect &&
147-
git show-ref --heads --tags --head >actual &&
147+
git show-ref --branches --tags --head >actual &&
148148
test_cmp expect actual &&
149149
150150
{
@@ -165,6 +165,14 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
165165
test_cmp expect actual
166166
'
167167

168+
test_expect_success 'show-ref --heads is deprecated and hidden' '
169+
test_expect_code 129 git show-ref -h >short-help &&
170+
test_grep ! -e --heads short-help &&
171+
git show-ref --heads >actual 2>warning &&
172+
test_grep ! deprecated warning &&
173+
test_cmp expect.branches actual
174+
'
175+
168176
test_expect_success 'show-ref --verify HEAD' '
169177
echo $(git rev-parse HEAD) HEAD >expect &&
170178
git show-ref --verify HEAD >actual &&

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)