When we use certain Git environment variables to find the Git directory
and the working tree, we want those values to work regardless of what
directory we're in. Currently we don't change the working directory,
but we soon will in order to mimic Git's behavior. In order to make
relative values of these environment variables work correctly once we
change directories, let's turn them into absolute canonical paths when
we set up the repository.
We save the old environment variables into a variable and pass this
variable to the helper for the git lfs env command, which wants to print
the original values, not our modified ones. Note that we can't make the
canonicalization conditional on the subcommand being run because the
configuration structure has been initialized by the time we get to
argument parsing and the configuration code invokes Git upon
initialization.
Because the Cygwin path canonicalization invokes a subprocess on Windows
and the subprocess code caches the environment, we must also reset the
cache after adjusting these environment variables so that future
subprocess invocations, like those for Git, work as expected with the
updated environment.
Because "config" is not a command, Cobra returns an error when
the user invokes "git lfs help config" on the command line,
so we just print an error message and the generic usage
instead of returning the same content as one gets from
"man git-lfs-config" for git-lfs-config(5).
This differs from Git's own support for running, for instance,
"git help gitrepository-layout" for gitrepository-layout(5)
or "git help githooks" for githooks(5).
Therefore we specifically check if the supplied argument
to the "help" command is "config" and in that case look up
a dummy argument so we can proceed.
If the user invokes "git-lfs --help", we tell them that there's no usage
text found for "--help". This isn't very helpful. Since what the user
probably wanted was to invoke the general help output, let's do that by
rewriting the command to "git-lfs", which is the topic for the general
help output.
This was initially broken upstream in
d6bf4ef243.
They tried to fix it with
ded646f978
but functionality was not actually restored. This takes the help
command code from
ded646f978
and explicitly sets it as the help command. On one hand this is a bug
that should arguably be fixed upstream, but on the other hand I believe
this is now the way they intend people to use the `help` functionality.
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.