Class UserConfigFile


public class UserConfigFile extends FileBasedConfig
User (global) git config based on two possible locations, ~/.gitconfig and $XDG_CONFIG_HOME/git/config.

For reading, both locations are considered, first the XDG file, then the file in the home directory. All updates occur in the last file read that exists, or in the home directory file if neither exists. In other words: if only the XDG file exists, it is updated, otherwise the home directory file is updated.

Since:
6.7
  • Constructor Details

  • Method Details

    • setStringList

      public void setStringList(String section, String subsection, String name, List<String> values)
      Description copied from class: Config
      Set a configuration value.
       [section "subsection"]
               name = value1
               name = value2
       
      Overrides:
      setStringList in class Config
      Parameters:
      section - section name, e.g "branch"
      subsection - optional subsection value, e.g. a branch name
      name - parameter name, e.g. "filemode"
      values - list of zero or more values for this key.
    • unset

      public void unset(String section, String subsection, String name)
      Description copied from class: Config
      Remove a configuration value.
      Overrides:
      unset in class Config
      Parameters:
      section - section name, e.g "branch"
      subsection - optional subsection value, e.g. a branch name
      name - parameter name, e.g. "filemode"
    • unsetSection

      public void unsetSection(String section, String subsection)
      Description copied from class: Config
      Remove all configuration values under a single section.
      Overrides:
      unsetSection in class Config
      Parameters:
      section - section name, e.g "branch"
      subsection - optional subsection value, e.g. a branch name
    • removeSection

      public boolean removeSection(String section, String subsection)
      Description copied from class: Config
      Removes all configuration values under a single section.
      Overrides:
      removeSection in class Config
      Parameters:
      section - section name, e.g "branch"
      subsection - optional subsection value, e.g. a branch name
      Returns:
      true if a section was present and was removed; false if the config was not changed (i.e., no such section was present)
    • isOutdated

      public boolean isOutdated()
      Description copied from class: FileBasedConfig
      Whether the currently loaded configuration file is outdated
      Overrides:
      isOutdated in class FileBasedConfig
      Returns:
      returns true if the currently loaded configuration file is older than the file on disk
    • load

      public void load() throws IOException, ConfigInvalidException
      Description copied from class: FileBasedConfig
      Load the configuration from the persistent store.

      If the configuration does not exist, this configuration is cleared, and thus behaves the same as though the backing store exists, but is empty.

      Load the configuration as a Git text style configuration file.

      If the file does not exist, this configuration is cleared, and thus behaves the same as though the file exists, but is empty.

      Overrides:
      load in class FileBasedConfig
      Throws:
      IOException - the configuration could not be read (but does exist).
      ConfigInvalidException - the configuration is not properly formatted.
    • save

      public void save() throws IOException
      Description copied from class: FileBasedConfig
      Save the configuration to the persistent store.

      Save the configuration as a Git text style configuration file.

      Warning: Although this method uses the traditional Git file locking approach to protect against concurrent writes of the configuration file, it does not ensure that the file has not been modified since the last read, which means updates performed by other objects accessing the same backing file may be lost.

      Overrides:
      save in class FileBasedConfig
      Throws:
      IOException - the configuration could not be written.