GitHoox.Glob (GitHoox v0.4.0)

Copy Markdown View Source

Path glob matching used by hook :files filters.

Supported tokens:

  • **/ — zero or more leading directory segments
  • ** — any sequence of characters, including /
  • * — any sequence of characters within a single segment
  • ? — exactly one non-/ character

All other characters are matched literally; regex metacharacters in the pattern are escaped before token expansion, so a literal . or + in the pattern matches itself.

Summary

Functions

Compile pattern to an anchored Regex.t().

Return true if file matches pattern.

Functions

compile(pattern)

@spec compile(GitHoox.glob()) :: Regex.t()

Compile pattern to an anchored Regex.t().

Call this once per pattern when matching against many files — otherwise use match?/2, which compiles on every call.

match?(file, pattern)

@spec match?(GitHoox.path(), GitHoox.glob()) :: boolean()

Return true if file matches pattern.

Anchored at both ends — partial matches do not count.

Examples

iex> GitHoox.Glob.match?("lib/foo.ex", "lib/*.ex")
true

iex> GitHoox.Glob.match?("lib/nested/bar.ex", "lib/**/*.ex")
true

iex> GitHoox.Glob.match?("README.md", "lib/**/*.ex")
false