When ConfigManager() is given a dataset, the 'git config --list' is
executed from its top-level directory. Otherwise, execution is from
the current working directory. Problematically, if the PWD belongs to
a repository, its configuration is considered for both reading and
writing. In practice this doesn't happen much in the code base.
There are two main paths to trigger it:
1) datalad.cfg, which isn't supposed to be attached to any dataset,
will contain the configuration for the PWD's
2) instantiating Dataset() with a path that does not yet exist while
the PWD belongs to another repo. In this case, Dataset.config
calls ConfigManager() with dataset=None. But once the dataset is
created, the configuration comes from the correct repository
The unmerged 7fe9f9a (BF: Prevent accidential read from AND write to
undesired datasets, dataladgh-4072) fixes the above issues by passing either
--system or --global to 'git config' when a dataset isn't specified or
its path doesn't exist. --system versus --global is chosen based on
whether ~/.gitconfig exists. This approach introduces other problems.
Currently the configuration from both --system and --global sources is
considered, but that change would limit it to just one of those
sources. Also, the approach assumes that the user's "global"
configuration is in ~/.gitconfig, but it could also be in
$XDG_CONFIG_HOME/git/config.
As an alternative fix that avoids passing --system or --global
explicitly, let's prevent 'git config' from reading or writing
repository-based configuration values whenever a dataset is not given.
Do this by setting $GIT_DIR to an empty string.
One argument against this is that, as far as I can see, the empty
string behavior isn't explicitly documented. However, based on trying
with Git v2.9.0 (2016) [*] and the latest Git (v2.25.0), it appears
this behavior is stable. And if the behavior does change, the tests
we have in place should detect it.
Fixes datalad#4071.
Supersedes and closes datalad#4072.
[*] This was the earliest Git I had luck compiling locally.