Git fork

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 <ps@pks.im>
Signed-off-by: Taylor Blau <me@ttaylorr.com>

authored by

Patrick Steinhardt and committed by
Taylor Blau
5ff36c9b 8c1bc2a7

+57
+7
Documentation/git-rev-parse.txt
··· 197 197 or `--all`. If a trailing '/{asterisk}' is intended, it must be given 198 198 explicitly. 199 199 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 + 200 207 --disambiguate=<prefix>:: 201 208 Show every object whose name begins with the given prefix. 202 209 The <prefix> must be at least 4 hexadecimal digits long to
+10
builtin/rev-parse.c
··· 876 876 continue; 877 877 } 878 878 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")); 879 881 handle_ref_opt(arg, "refs/heads/"); 880 882 continue; 881 883 } 882 884 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")); 883 887 handle_ref_opt(arg, "refs/tags/"); 884 888 continue; 885 889 } ··· 888 892 continue; 889 893 } 890 894 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")); 891 897 handle_ref_opt(arg, "refs/remotes/"); 892 898 continue; 893 899 } 894 900 if (skip_prefix(arg, "--exclude=", &arg)) { 895 901 add_ref_exclusion(&ref_excludes, arg); 902 + continue; 903 + } 904 + if (skip_prefix(arg, "--exclude-hidden=", &arg)) { 905 + exclude_hidden_refs(&ref_excludes, arg); 896 906 continue; 897 907 } 898 908 if (!strcmp(arg, "--show-toplevel")) {
+40
t/t6018-rev-list-glob.sh
··· 187 187 compare rev-parse "--exclude=upstream/x --remotes=upstream/*" "upstream/one upstream/two" 188 188 ' 189 189 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 + 190 230 test_expect_success 'rev-list --exclude=glob with --branches=glob' ' 191 231 compare rev-list "--exclude=subspace-* --branches=sub*" "subspace/one subspace/two" 192 232 '