Skip to content

Commit 81c365b

Browse files
committed
Merge branch 'jk/proto-v2-ref-prefix-fix'
"git ls-remote $there foo" was broken by recent update for the protocol v2 and stopped showing refs that match 'foo' that are not refs/{heads,tags}/foo, which has been fixed. * jk/proto-v2-ref-prefix-fix: ls-remote: pass heads/tags prefixes to transport ls-remote: do not send ref prefixes for patterns
2 parents 879a8d4 + 6a139cd commit 81c365b

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

builtin/ls-remote.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,15 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
8888
int i;
8989
pattern = xcalloc(argc, sizeof(const char *));
9090
for (i = 1; i < argc; i++) {
91-
const char *glob;
9291
pattern[i - 1] = xstrfmt("*/%s", argv[i]);
93-
94-
glob = strchr(argv[i], '*');
95-
if (glob)
96-
argv_array_pushf(&ref_prefixes, "%.*s",
97-
(int)(glob - argv[i]), argv[i]);
98-
else
99-
expand_ref_prefix(&ref_prefixes, argv[i]);
10092
}
10193
}
10294

95+
if (flags & REF_TAGS)
96+
argv_array_push(&ref_prefixes, "refs/tags/");
97+
if (flags & REF_HEADS)
98+
argv_array_push(&ref_prefixes, "refs/heads/");
99+
103100
remote = remote_get(dest);
104101
if (!remote) {
105102
if (dest)

t/t5512-ls-remote.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,22 @@ test_expect_success 'ls-remote works outside repository' '
302302
nongit git ls-remote dst.git
303303
'
304304

305+
test_expect_success 'ls-remote patterns work with all protocol versions' '
306+
git for-each-ref --format="%(objectname) %(refname)" \
307+
refs/heads/master refs/remotes/origin/master >expect &&
308+
git -c protocol.version=1 ls-remote . master >actual.v1 &&
309+
test_cmp expect actual.v1 &&
310+
git -c protocol.version=2 ls-remote . master >actual.v2 &&
311+
test_cmp expect actual.v2
312+
'
313+
314+
test_expect_success 'ls-remote prefixes work with all protocol versions' '
315+
git for-each-ref --format="%(objectname) %(refname)" \
316+
refs/heads/ refs/tags/ >expect &&
317+
git -c protocol.version=1 ls-remote --heads --tags . >actual.v1 &&
318+
test_cmp expect actual.v1 &&
319+
git -c protocol.version=2 ls-remote --heads --tags . >actual.v2 &&
320+
test_cmp expect actual.v2
321+
'
322+
305323
test_done

0 commit comments

Comments
 (0)