Git.Commands.CheckIgnore (git v0.4.0)

Copy Markdown View Source

Implements the Git.Command behaviour for git check-ignore.

Checks whether given paths are ignored by .gitignore rules. Supports verbose output showing which pattern matched and non-matching mode.

Stdin mode (--stdin) is intentionally not supported because it requires stdin piping which cannot be driven programmatically via System.cmd/3.

Summary

Functions

Returns the argument list for git check-ignore.

Parses the output of git check-ignore.

Types

t()

@type t() :: %Git.Commands.CheckIgnore{
  no_index: boolean(),
  non_matching: boolean(),
  paths: [String.t()],
  quiet: boolean(),
  verbose: boolean()
}

Functions

args(command)

@spec args(t()) :: [String.t()]

Returns the argument list for git check-ignore.

Examples

iex> Git.Commands.CheckIgnore.args(%Git.Commands.CheckIgnore{paths: ["build/", "tmp.log"]})
["check-ignore", "build/", "tmp.log"]

iex> Git.Commands.CheckIgnore.args(%Git.Commands.CheckIgnore{paths: ["foo"], verbose: true})
["check-ignore", "-v", "foo"]

iex> Git.Commands.CheckIgnore.args(%Git.Commands.CheckIgnore{paths: ["foo"], verbose: true, non_matching: true})
["check-ignore", "-v", "-n", "foo"]

iex> Git.Commands.CheckIgnore.args(%Git.Commands.CheckIgnore{paths: ["foo"], no_index: true})
["check-ignore", "--no-index", "foo"]

iex> Git.Commands.CheckIgnore.args(%Git.Commands.CheckIgnore{paths: ["foo"], quiet: true})
["check-ignore", "-q", "foo"]

parse_output(stdout, exit_code)

@spec parse_output(String.t(), non_neg_integer()) ::
  {:ok, [String.t()] | [map()]} | {:error, {String.t(), non_neg_integer()}}

Parses the output of git check-ignore.

  • Default mode: returns {:ok, [String.t()]} with the list of ignored paths.
  • Verbose mode: returns {:ok, [map]} where each map has :source, :line_number, :pattern, and :path keys.
  • Exit code 1 means no paths matched, which returns {:ok, []} (not an error).