Skip to content

Commit 40f327f

Browse files
ttaylorrgitster
authored andcommitted
transport.c: introduce core.alternateRefsPrefixes
The recently-introduced "core.alternateRefsCommand" allows callers to specify with high flexibility the tips that they wish to advertise from alternates. This flexibility comes at the cost of some inconvenience when the caller only wishes to limit the advertisement to one or more prefixes. For example, to advertise only tags, a caller using 'core.alternateRefsCommand' would have to do: $ git config core.alternateRefsCommand ' \ f() { git -C "$1" for-each-ref \ refs/tags --format="%(objectname)" }; f "$@"' The above is cumbersome to write, so let's introduce a "core.alternateRefsPrefixes" to address this common case. Instead, the caller can run: $ git config core.alternateRefsPrefixes 'refs/tags' Which will behave identically to the longer example using "core.alternateRefsCommand". Since the value of "core.alternateRefsPrefixes" is appended to 'git for-each-ref' and then executed, include a "--" before taking the configured value to avoid misinterpreting arguments as flags to 'git for-each-ref'. In the case that the caller wishes to specify multiple prefixes, they may separate them by whitespace. If "core.alternateRefsCommand" is set, it will take precedence over "core.alternateRefsPrefixes". Signed-off-by: Taylor Blau <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89284c1 commit 40f327f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Documentation/config.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ Note that you cannot generally put `git for-each-ref` directly into the config
627627
value, as it does not take a repository path as an argument (but you can wrap
628628
the command above in a shell script).
629629

630+
core.alternateRefsPrefixes::
631+
When listing references from an alternate, list only references that begin
632+
with the given prefix. Prefixes match as if they were given as arguments to
633+
linkgit:git-for-each-ref[1]. To list multiple prefixes, separate them with
634+
whitespace. If `core.alternateRefsCommand` is set, setting
635+
`core.alternateRefsPrefixes` has no effect.
636+
630637
core.bare::
631638
If true this repository is assumed to be 'bare' and has no
632639
working directory associated with it. If this is the case a

t/t5410-receive-pack-alternates.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ test_expect_success 'with core.alternateRefsCommand' '
3030
test_cmp expect actual.haves
3131
'
3232

33+
test_expect_success 'with core.alternateRefsPrefixes' '
34+
test_config -C fork core.alternateRefsPrefixes "refs/heads/private" &&
35+
git rev-parse private/branch >expect &&
36+
printf "0000" | git receive-pack fork >actual &&
37+
extract_haves <actual >actual.haves &&
38+
test_cmp expect actual.haves
39+
'
40+
3341
test_done

transport.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,11 @@ static void fill_alternate_refs_command(struct child_process *cmd,
13411341
argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path);
13421342
argv_array_push(&cmd->args, "for-each-ref");
13431343
argv_array_push(&cmd->args, "--format=%(objectname)");
1344+
1345+
if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
1346+
argv_array_push(&cmd->args, "--");
1347+
argv_array_split(&cmd->args, value);
1348+
}
13441349
}
13451350

13461351
cmd->env = local_repo_env;

0 commit comments

Comments
 (0)