Per git-config's man page, include.* directives are not respected by
default when asked to evaluate a specific file (whether via --global,
--file /path/to/.gitconfig, or GIT_CONFIG=/path/to/.gitconfig).
This patch ensures that, if GIT_CONFIG is set in the environment when
e.g. git-lfs-push is invoked, config directives from included files are
evaluated.
This is important if, for example, an included file contains a
url.<foo>.insteadOf directive or lfs.<foo>.locksverify directive that's
shared between many repositories.
Currently we only read .lfsconfig from the working tree. This is better
than nothing, but it means that if there's an LFS file that starts with
a name earlier than .lfsconfig, we won't read the proper config file,
and we won't use any LFS remote URLs that are located in that file.
If the file is missing, let's additionally read from the index, if
there's a working tree, and then from HEAD. If the repository is bare,
let's just read from HEAD. This is very similar to what Git does for
.gitmodules.
It does, however, differ in one significant way: Git will read from the
index first if it's doing a checkout, since that might have newer
information. We don't do that here, since it's not totally clear that
we can articulate all the cases where that occurs in Git LFS, but we
explicitly allow for the possibility of changing the behavior in the
future and document the feature accordingly.
We no longer read the file .lfsconfig from a bare repository, but that
we did this in the first place was very questionable and pretty clearly
a bug, so it's intentional that we no longer do.
Trace all command execution at the time when the command starts.
Previously, only "simple" execution created trace entries, leading to
mysterious gaps in trace logs where time passed but it looked like
nothing was happening.
We add a --worktree option to "git lfs install" and "git lfs
uninstall" and pass it through to "git config", but only when
the Git version is at least 2.20.0, as prior Git versions do
not support the --worktree option.
We do some minor housekeeping to correct and clarify comments
which didn't match their find/set/unset functions, and we move
one function so we have a consistent ordering within each type.
We're going to need the environment variables in the object scanner, so
pass the appropriate Environment instance down into the object scanner.
Use an interface to avoid an import loop between the git and config
packages.
Note that the environment is not yet used, but will be in a future
commit.
There are some cases, notably in tests, where we do not want to write to
the filesystem. In such cases, it's better to return an error and let
each call site determine whether or not that error should be fatal.
Add a NewReadOnlyConfig constructor that works the same way as the
existing constructor, but simply sets a flag to block any writes. Make
the functions that write to the filesystem go through a wrapper that
checks for read-only status and have them fail.