6

What type of "pattern" does git ls-remote take?

man git-ls-remote says:

   <refs>...
       When unspecified, all references, after filtering done with --heads
       and --tags, are shown. When <refs>... are specified, only references
       matching the given patterns are displayed.

It is a POSIX shell glob, regex, gitignore pattern, ...?

Tom Hale
  • 40,825
  • 36
  • 187
  • 242
  • 3
    Reference patterns are always shell-style globs. – torek Oct 05 '18 at 15:04
  • @torek Very helpful. You should post this as the answer. I found this helpful in testing those patterns too. http://www.globtester.com/ – Jazzepi Oct 07 '19 at 00:12

2 Answers2

3

Indeed, the documentation of ls-remote doesn't say much, but you can find this information in other pages. For example the documentation for git tag -l says:

The pattern is a shell wildcard (i.e., matched using fnmatch(3)).

As far as I can tell git only supports the basic glob syntax but doesn't support "extended patterns" provided by the FNM_EXTMATCH.

I think the filtering is actually implemented by wildmatch(), so the behavior may differ from the standard fnmatch.

Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81
0

Note that Git 2.40 (Q1 2023) does slightly update the definition of a pattern for git ls-remote.

See commit d9ec3b0, commit baebde7 (10 Feb 2023) by Jeff King (peff).
(Merged by Junio C Hamano -- gitster -- in commit 6aac634, 22 Feb 2023)

doc/ls-remote: clarify pattern format

Signed-off-by: Jeff King

We document that you can specify "refs" to ls-remote, but we don't explain any further than that they are "matched" as patterns.
Since this can be interpreted in a lot of ways, let's clarify that they are tail-matched globs.

Likewise, let's use the word "patterns" to refer to them consistently, rather than "refs" (both here and in the quick "-h" help), and mention more explicitly that only one pattern needs to be matched (though there is also an example already that shows this in action).

git ls-remote now includes in its man page:

[--symref] [<repository> [<patterns>...]]

git ls-remote now includes in its man page:

<patterns>...:

When unspecified, all references, after filtering done with --heads and --tags, are shown.

When <patterns>... are specified, only references matching one or more of the given patterns are displayed.
Each pattern is interpreted as a glob which is matched against the "tail" of a ref, starting either from the start of the ref (so a full name like refs/heads/foo matches) or from a slash separator (so bar matches refs/heads/bar but not refs/heads/foobar).

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250