Skip to content

Commit 824a0be

Browse files
committed
Merge branch 'jk/negative-hiderefs'
A negative !ref entry in multi-value transfer.hideRefs configuration can be used to say "don't hide this one". * jk/negative-hiderefs: refs: support negative transfer.hideRefs docs/config.txt: reorder hideRefs config
2 parents 138014c + 2bc31d1 commit 824a0be

File tree

3 files changed

+56
-22
lines changed

3 files changed

+56
-22
lines changed

Documentation/config.txt

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,13 +2313,10 @@ receive.denyNonFastForwards::
23132313
set when initializing a shared repository.
23142314

23152315
receive.hideRefs::
2316-
String(s) `receive-pack` uses to decide which refs to omit
2317-
from its initial advertisement. Use more than one
2318-
definitions to specify multiple prefix strings. A ref that
2319-
are under the hierarchies listed on the value of this
2320-
variable is excluded, and is hidden when responding to `git
2321-
push`, and an attempt to update or delete a hidden ref by
2322-
`git push` is rejected.
2316+
This variable is the same as `transfer.hideRefs`, but applies
2317+
only to `receive-pack` (and so affects pushes, but not fetches).
2318+
An attempt to update or delete a hidden ref by `git push` is
2319+
rejected.
23232320

23242321
receive.updateServerInfo::
23252322
If set to true, git-receive-pack will run git-update-server-info
@@ -2607,9 +2604,18 @@ transfer.fsckObjects::
26072604
Defaults to false.
26082605

26092606
transfer.hideRefs::
2610-
This variable can be used to set both `receive.hideRefs`
2611-
and `uploadpack.hideRefs` at the same time to the same
2612-
values. See entries for these other variables.
2607+
String(s) `receive-pack` and `upload-pack` use to decide which
2608+
refs to omit from their initial advertisements. Use more than
2609+
one definition to specify multiple prefix strings. A ref that is
2610+
under the hierarchies listed in the value of this variable is
2611+
excluded, and is hidden when responding to `git push` or `git
2612+
fetch`. See `receive.hideRefs` and `uploadpack.hideRefs` for
2613+
program-specific versions of this config.
2614+
+
2615+
You may also include a `!` in front of the ref name to negate the entry,
2616+
explicitly exposing it, even if an earlier entry marked it as hidden.
2617+
If you have multiple hideRefs values, later entries override earlier ones
2618+
(and entries in more-specific config files override less-specific ones).
26132619

26142620
transfer.unpackLimit::
26152621
When `fetch.unpackLimit` or `receive.unpackLimit` are
@@ -2624,13 +2630,10 @@ uploadarchive.allowUnreachable::
26242630
`false`.
26252631

26262632
uploadpack.hideRefs::
2627-
String(s) `upload-pack` uses to decide which refs to omit
2628-
from its initial advertisement. Use more than one
2629-
definitions to specify multiple prefix strings. A ref that
2630-
are under the hierarchies listed on the value of this
2631-
variable is excluded, and is hidden from `git ls-remote`,
2632-
`git fetch`, etc. An attempt to fetch a hidden ref by `git
2633-
fetch` will fail. See also `uploadpack.allowTipSHA1InWant`.
2633+
This variable is the same as `transfer.hideRefs`, but applies
2634+
only to `upload-pack` (and so affects only fetches, not pushes).
2635+
An attempt to fetch a hidden ref by `git fetch` will fail. See
2636+
also `uploadpack.allowTipSHA1InWant`.
26342637

26352638
uploadpack.allowTipSHA1InWant::
26362639
When `uploadpack.hideRefs` is in effect, allow `upload-pack`

refs.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,17 +4371,25 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
43714371

43724372
int ref_is_hidden(const char *refname)
43734373
{
4374-
struct string_list_item *item;
4374+
int i;
43754375

43764376
if (!hide_refs)
43774377
return 0;
4378-
for_each_string_list_item(item, hide_refs) {
4378+
for (i = hide_refs->nr - 1; i >= 0; i--) {
4379+
const char *match = hide_refs->items[i].string;
4380+
int neg = 0;
43794381
int len;
4380-
if (!starts_with(refname, item->string))
4382+
4383+
if (*match == '!') {
4384+
neg = 1;
4385+
match++;
4386+
}
4387+
4388+
if (!starts_with(refname, match))
43814389
continue;
4382-
len = strlen(item->string);
4390+
len = strlen(match);
43834391
if (!refname[len] || refname[len] == '/')
4384-
return 1;
4392+
return !neg;
43854393
}
43864394
return 0;
43874395
}

t/t5512-ls-remote.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ test_expect_success 'Report match with --exit-code' '
128128
test_cmp expect actual
129129
'
130130

131+
test_expect_success 'set up some extra tags for ref hiding' '
132+
git tag magic/one &&
133+
git tag magic/two
134+
'
135+
131136
for configsection in transfer uploadpack
132137
do
133138
test_expect_success "Hide some refs with $configsection.hiderefs" '
@@ -138,6 +143,24 @@ do
138143
sed -e "/ refs\/tags\//d" >expect &&
139144
test_cmp expect actual
140145
'
146+
147+
test_expect_success "Override hiding of $configsection.hiderefs" '
148+
test_when_finished "test_unconfig $configsection.hiderefs" &&
149+
git config --add $configsection.hiderefs refs/tags &&
150+
git config --add $configsection.hiderefs "!refs/tags/magic" &&
151+
git config --add $configsection.hiderefs refs/tags/magic/one &&
152+
git ls-remote . >actual &&
153+
grep refs/tags/magic/two actual &&
154+
! grep refs/tags/magic/one actual
155+
'
156+
141157
done
142158

159+
test_expect_success 'overrides work between mixed transfer/upload-pack hideRefs' '
160+
test_config uploadpack.hiderefs refs/tags &&
161+
test_config transfer.hiderefs "!refs/tags/magic" &&
162+
git ls-remote . >actual &&
163+
grep refs/tags/magic actual
164+
'
165+
143166
test_done

0 commit comments

Comments
 (0)