Xgit v0.7.3 Xgit.ConfigFile View Source

This GenServer monitors and potentially updates the contents of an on-disk git config file.

See https://git-scm.com/docs/git-config for details on the config file format.

Link to this section Summary

Types

Error codes that can be returned by add_entries/3.

Error codes that can be returned by get_entries/2.

Error codes that can be returned by remove_entries/2.

t()

Process ID for an Xgit.ConfigFile process.

Functions

Add one or more new entries to an existing config.

Returns a specification to start this module under a supervisor.

Return any configuration entries that match the requested search.

Removes all configuration entries that match the requested search.

Start a ConfigFile for a config file at the given path.

Link to this section Types

Link to this type

add_entries_reason()

View Source
add_entries_reason() :: File.posix() | :replacing_multivar

Error codes that can be returned by add_entries/3.

Link to this type

get_entries_reason()

View Source
get_entries_reason() :: File.posix()

Error codes that can be returned by get_entries/2.

Link to this type

remove_entries_reason()

View Source
remove_entries_reason() :: File.posix()

Error codes that can be returned by remove_entries/2.

Process ID for an Xgit.ConfigFile process.

Link to this section Functions

Link to this function

add_entries(config_file, entries, opts \\ [])

View Source
add_entries(config_file :: t(), entries :: [Xgit.ConfigEntry.t()],
  add?: boolean(),
  replace_all?: boolean()
) :: :ok | {:error, config_file :: add_entries_reason()}

Add one or more new entries to an existing config.

The entries need not be sorted. However, if multiple values are provided for the same variable (section, subsection, name tuple), they will be added in the order provided here.

Parameters

entries (list of Xgit.ConfigEntry) entries to be added

Options

  • add?: if true, adds these entries to any that may already exist
  • replace_all?: if true, removes all existing entries that match any keys provided

See also the :remove_all option for the value member of Xgit.ConfigEntry.

Return Values

:ok if successful.

{:error, :replacing_multivar} if the existing variable has multiple variables. Replacing such a variable requires either add?: true or replace_all?: true.

{:error, reason} if unable. reason is likely a POSIX error code.

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

get_entries(config_file, opts \\ [])

View Source
get_entries(config_file :: t(),
  section: String.t(),
  subsection: String.t(),
  name: String.t()
) ::
  {:ok, entries :: [Xgit.ConfigEntry.t()]}
  | {:error, reason :: get_entries_reason()}

Return any configuration entries that match the requested search.

Entries will be returned in the order in which they appeared in the underlying file.

Options

  • section: (String) if provided, only returns entries in the named section
  • subsection: (String) if provided, only returns entries in the named subsection (only meaningful if section is also provided)
  • name: (String) if provided, only returns entries with the given variable name (only meaningful if section is also provided)

If section is provided but subsection is not, then only items within the top-level section (i.e. with no subsection) will be matched.

If no options are provided, returns all entries.

Return Values

{:ok, [entries]} where entries is a list of Xgit.ConfigEntry structs that match the search parameters.

{:error, reason} if unable. reason is likely a POSIX error code.

Link to this function

remove_entries(config_file, opts \\ [])

View Source
remove_entries(config_file :: t(),
  section: String.t(),
  subsection: String.t(),
  name: String.t()
) :: :ok | {:error, reason :: remove_entries_reason()}

Removes all configuration entries that match the requested search.

Options

  • section: (String) if provided, only removes entries in the named section
  • subsection: (String) if provided, only removes entries in the named subsection (only meaningful if section is also provided)
  • name: (String) if provided, only removes entries with the given variable name (only meaningful if section is also provided)

If section is provided but subsection is not, then only items within the top-level section (i.e. with no subsection) will be removed.

If no options are provided, removes all entries.

Return Values

:ok if able to complete the operation (regardless of whether any matching entries were found and removed).

{:error, reason} if unable. reason is likely a POSIX error code.

Link to this function

start_link(path)

View Source
start_link(path :: Path.t()) :: GenServer.on_start()

Start a ConfigFile for a config file at the given path.

The path (including parent directory) needs to exist, but there need not be a file at this path.