Skip to content

Commit 5ff36c9

Browse files
pks-tttaylorr
authored andcommitted
rev-parse: add --exclude-hidden= option
Add a new `--exclude-hidden=` option that is similar to the one we just added to git-rev-list(1). Given a section name `uploadpack` or `receive` as argument, it causes us to exclude all references that would be hidden by the respective `$section.hideRefs` configuration. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 8c1bc2a commit 5ff36c9

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

Documentation/git-rev-parse.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ respectively, and they must begin with `refs/` when applied to `--glob`
197197
or `--all`. If a trailing '/{asterisk}' is intended, it must be given
198198
explicitly.
199199

200+
--exclude-hidden=[receive|uploadpack]::
201+
Do not include refs that would be hidden by `git-receive-pack` or
202+
`git-upload-pack` by consulting the appropriate `receive.hideRefs` or
203+
`uploadpack.hideRefs` configuration along with `transfer.hideRefs` (see
204+
linkgit:git-config[1]). This option affects the next pseudo-ref option
205+
`--all` or `--glob` and is cleared after processing them.
206+
200207
--disambiguate=<prefix>::
201208
Show every object whose name begins with the given prefix.
202209
The <prefix> must be at least 4 hexadecimal digits long to

builtin/rev-parse.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,10 +876,14 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
876876
continue;
877877
}
878878
if (opt_with_value(arg, "--branches", &arg)) {
879+
if (ref_excludes.hidden_refs_configured)
880+
return error(_("--exclude-hidden cannot be used together with --branches"));
879881
handle_ref_opt(arg, "refs/heads/");
880882
continue;
881883
}
882884
if (opt_with_value(arg, "--tags", &arg)) {
885+
if (ref_excludes.hidden_refs_configured)
886+
return error(_("--exclude-hidden cannot be used together with --tags"));
883887
handle_ref_opt(arg, "refs/tags/");
884888
continue;
885889
}
@@ -888,13 +892,19 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
888892
continue;
889893
}
890894
if (opt_with_value(arg, "--remotes", &arg)) {
895+
if (ref_excludes.hidden_refs_configured)
896+
return error(_("--exclude-hidden cannot be used together with --remotes"));
891897
handle_ref_opt(arg, "refs/remotes/");
892898
continue;
893899
}
894900
if (skip_prefix(arg, "--exclude=", &arg)) {
895901
add_ref_exclusion(&ref_excludes, arg);
896902
continue;
897903
}
904+
if (skip_prefix(arg, "--exclude-hidden=", &arg)) {
905+
exclude_hidden_refs(&ref_excludes, arg);
906+
continue;
907+
}
898908
if (!strcmp(arg, "--show-toplevel")) {
899909
const char *work_tree = get_git_work_tree();
900910
if (work_tree)

t/t6018-rev-list-glob.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,46 @@ test_expect_success 'rev-parse --exclude=ref with --remotes=glob' '
187187
compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two"
188188
'
189189

190+
for section in receive uploadpack
191+
do
192+
test_expect_success "rev-parse --exclude-hidden=$section with --all" '
193+
compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags" "--exclude-hidden=$section --all"
194+
'
195+
196+
test_expect_success "rev-parse --exclude-hidden=$section with --all" '
197+
compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --all" "--exclude-hidden=$section --all"
198+
'
199+
200+
test_expect_success "rev-parse --exclude-hidden=$section with --glob" '
201+
compare "-c transfer.hideRefs=refs/heads/subspace/ rev-parse" "--exclude=refs/heads/subspace/* --glob=refs/heads/*" "--exclude-hidden=$section --glob=refs/heads/*"
202+
'
203+
204+
test_expect_success "rev-parse --exclude-hidden=$section can be passed once per pseudo-ref" '
205+
compare "-c transfer.hideRefs=refs/remotes/ rev-parse" "--branches --tags --branches --tags" "--exclude-hidden=$section --all --exclude-hidden=$section --all"
206+
'
207+
208+
test_expect_success "rev-parse --exclude-hidden=$section can only be passed once per pseudo-ref" '
209+
echo "fatal: --exclude-hidden= passed more than once" >expected &&
210+
test_must_fail git rev-parse --exclude-hidden=$section --exclude-hidden=$section 2>err &&
211+
test_cmp expected err
212+
'
213+
214+
for pseudoopt in branches tags remotes
215+
do
216+
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt" '
217+
echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
218+
test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt 2>err &&
219+
test_cmp expected err
220+
'
221+
222+
test_expect_success "rev-parse --exclude-hidden=$section fails with --$pseudoopt=pattern" '
223+
echo "error: --exclude-hidden cannot be used together with --$pseudoopt" >expected &&
224+
test_must_fail git rev-parse --exclude-hidden=$section --$pseudoopt=pattern 2>err &&
225+
test_cmp expected err
226+
'
227+
done
228+
done
229+
190230
test_expect_success 'rev-list --exclude=glob with --branches=glob' '
191231
compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two"
192232
'

0 commit comments

Comments
 (0)