Honor the repository permssions set with the umask or
core.sharedRepository when creating directories by using tools.MkdirAll.
Pass an appropriate configuration or filesystem object through as needed
to ensure that we can query the proper permissions. Add a test that
these code paths work by cloning a new repository and then performing
some operations on it.
Note that in the test, we match patterns with either the setgid bit
clear or set, since it may be set or not depending on whether the system
has SysV or BSD group semantics.
We have several places in the code base where we have a Filesystem
object but no Configuration object, namely in the transfer queue. Pass
the repository permissions down into the Filesystem object and expose
them using the same interface as the config object, so we can use either
one as the instance when calling tools.MkdirAll.
existsAlternate supposes a valid alternate string, and sanitizes it. One
case of this is unquoting a quoted string using strconv.Unquote, which
we trigger if and only if the string begins with a double-quote
character, ".
This function was extracted from a similar-looking function that ignores
comments (i.e., those strings beginning with '#'), so a typo was made
here.
This patch fixes that.
The Git documentation also mentions that the
"$GIT_ALTERNATE_OBJECT_DIRECTORIES" environment variable is a valid way
to configure object database remotes [1]:
2. You could be using the `objects/info/alternates` or
`$GIT_ALTERNATE_OBJECT_DIRECTORIES` mechanisms to borrow objects
from other object stores.
Let's support the same by using the last commit, taking in a handle on
the operating-system configuration and using that in addition to the
list found in .git/objects/info/alternates.
[1]: https://git-scm.com/docs/gitrepository-layout#gitrepository-layout-objectsinfoalternates
In a subsequent commit, we will support reading a list of ODB alternates
from the OS environment variable, "$GIT_ALTERNATE_OBJECT_DIRECTORIES".
To prepare for this, let's extract a function that determines whether or
not a given string is suitable as an alternates directory.
Like in upstream Git, Git LFS supports "object database alternates"
(described in [1]) to link several object databases together.
We have supported this feature since [2] but read the entire
.git/objects/info/alternates in one single buffer via ioutil.ReadFile
and checked if a directory existed at that location.
If a user specified multiple alternates, then this will fail. Git LFS
will look for a directory that has newlines in it, when what it should
be doing is splitting that list by the '\n' character and checking each
directory if it exists.
Let's do that, and also return a []string, instead of a single string,
to indicate that there might be multiple alternates in a repository.
[1]: https://git-scm.com/docs/gitrepository-layout#gitrepository-layout-objectsinfoalternates
[2]: https://github.com/git-lfs/git-lfs/pull/1007/files