~/.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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jgit.lib.Config
Config.ConfigEnum, Config.SectionParser<T>
-
Constructor Summary
ConstructorsConstructorDescriptionUserConfigFile
(Config parent, File config, File xdgConfig, FS fileSystem) Creates a newUserConfigFile
. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Whether the currently loaded configuration file is outdatedvoid
load()
Load the configuration from the persistent store.boolean
removeSection
(String section, String subsection) Removes all configuration values under a single section.void
save()
Save the configuration to the persistent store.void
Set a configuration value.void
Remove a configuration value.void
unsetSection
(String section, String subsection) Remove all configuration values under a single section.Methods inherited from class org.eclipse.jgit.storage.file.FileBasedConfig
clear, getFile, notifyUponTransientChanges, readIncludedConfig, toString
Methods inherited from class org.eclipse.jgit.lib.Config
addChangeListener, fireConfigChangedEvent, fromText, get, getBaseConfig, getBoolean, getBoolean, getEnum, getEnum, getInt, getInt, getIntInRange, getIntInRange, getLong, getLong, getNames, getNames, getNames, getNames, getPath, getRefSpecs, getSections, getString, getStringList, getSubsections, getTimeUnit, isMissing, isUtf8, setBoolean, setEnum, setInt, setLong, setString, setTypedConfigGetter, toText, uncache
-
Constructor Details
-
UserConfigFile
public UserConfigFile(Config parent, @NonNull File config, @NonNull File xdgConfig, @NonNull FS fileSystem) Creates a newUserConfigFile
.- Parameters:
parent
- parentConfig
; may benull
config
-File
for~/.gitconfig
xdgConfig
-File
for$XDG_CONFIG_HOME/.gitconfig
fileSystem
-FS
to use for the two files; normallyFS.DETECTED
-
-
Method Details
-
setStringList
Description copied from class:Config
Set a configuration value.[section "subsection"] name = value1 name = value2
- Overrides:
setStringList
in classConfig
- Parameters:
section
- section name, e.g "branch"subsection
- optional subsection value, e.g. a branch namename
- parameter name, e.g. "filemode"values
- list of zero or more values for this key.
-
unset
Description copied from class:Config
Remove a configuration value. -
unsetSection
Description copied from class:Config
Remove all configuration values under a single section.- Overrides:
unsetSection
in classConfig
- Parameters:
section
- section name, e.g "branch"subsection
- optional subsection value, e.g. a branch name
-
removeSection
Description copied from class:Config
Removes all configuration values under a single section.- Overrides:
removeSection
in classConfig
- 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 classFileBasedConfig
- Returns:
- returns true if the currently loaded configuration file is older than the file on disk
-
load
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 classFileBasedConfig
- Throws:
IOException
- the configuration could not be read (but does exist).ConfigInvalidException
- the configuration is not properly formatted.
-
save
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 classFileBasedConfig
- Throws:
IOException
- the configuration could not be written.
-