Skip to content

Commit 607c3d3

Browse files
committed
show-ref: 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 b773fb8 commit 607c3d3

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

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/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>...]"),
@@ -188,7 +188,7 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
188188

189189
struct patterns_options {
190190
int show_head;
191-
int heads_only;
191+
int branches_only;
192192
int tags_only;
193193
};
194194

@@ -206,8 +206,8 @@ static int cmd_show_ref__patterns(const struct patterns_options *opts,
206206

207207
if (opts->show_head)
208208
head_ref(show_ref, &show_ref_data);
209-
if (opts->heads_only || opts->tags_only) {
210-
if (opts->heads_only)
209+
if (opts->branches_only || opts->tags_only) {
210+
if (opts->branches_only)
211211
for_each_fullref_in("refs/heads/", show_ref, &show_ref_data);
212212
if (opts->tags_only)
213213
for_each_fullref_in("refs/tags/", show_ref, &show_ref_data);
@@ -286,8 +286,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
286286
struct show_one_options show_one_opts = {0};
287287
int verify = 0, exists = 0;
288288
const struct option show_ref_options[] = {
289-
OPT_BOOL(0, "tags", &patterns_opts.tags_only, N_("only show tags (can be combined with heads)")),
290-
OPT_BOOL(0, "heads", &patterns_opts.heads_only, N_("only show heads (can be combined with tags)")),
289+
OPT_BOOL(0, "tags", &patterns_opts.tags_only, N_("only show tags (can be combined with branches)")),
290+
OPT_BOOL(0, "branches", &patterns_opts.branches_only, N_("only show branches (can be combined with tags)")),
291+
OPT_HIDDEN_BOOL(0, "heads", &patterns_opts.branches_only,
292+
N_("deprecated synonym for --branches")),
291293
OPT_BOOL(0, "exists", &exists, N_("check for reference existence without resolving")),
292294
OPT_BOOL(0, "verify", &verify, N_("stricter reference checking, "
293295
"requires exact ref path")),

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 &&

0 commit comments

Comments
 (0)