Commit Graph

18 Commits

Author SHA1 Message Date
brian m. carlson
69b6cb30ff
subprocess: make strings translatable 2022-01-18 17:38:25 +00:00
brian m. carlson
59f1496289
subprocess: don't initialize environment at startup
Currently, the subprocess package reads from the environment as it's
created at startup when the init function is called.  However, we'll
soon want to modify the environment in this case before it gets
processed, so let's change the code to use a mutex to initialize the
environment once before using it and simply call that before using the
environment we've set up.

We'll want to reset the environment as well in a future commit, so let's
be sure to add a function for that.  We reuse the same internal function
and just ignore the return value to make our code paths simpler.
2020-10-14 16:49:23 +00:00
Billy Keyes
f953f1eb38 subprocess: trace all command execution
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.
2020-07-01 12:13:29 -07:00
Patrick Lühne
7838572d72
Support submodule.recurse = true
Git’s configuration option submodule.recurse makes it more convenient to
use submodules. If set to true, top-level checkouts will recurse into
all submodules. Additionally, Git will pass an environment variable
called GIT_INTERNAL_SUPER_PREFIX to the respective submodule’s path
relative to its parent repository to each child process, including git
lfs filter-process.

In turn, Git LFS spawns a couple of Git processes, for instance, when
checking the minimum required Git version, reading Git configuration
values, or obtaining the object name of a commit with git rev-parse.

In the current implementation, Git LFS would forward the environment
variable GIT_INTERNAL_SUPER_PREFIX to Git unchanged. This is problematic
because the presence of this environment variable will make Git behave
as if the command-line option --super-prefix had been passed to the
respective Git command. However, many commands don’t support the
--super-prefix command-line option. This includes git version, git
config, and git rev-parse. Consequently, these Git processes, as spawned
by Git LFS, would immediately fail with a usage error.

In short, users of submodule.recurse = true would get errors when
working in repositories with at least one Git-LFS-enabled submodule.

This patch fixes the issue by removing the GIT_INTERNAL_SUPER_PREFIX
environment variable from the environment Git LFS passes to Git child
processes.
2020-03-10 01:59:46 +01:00
Marat Radchenko
c5ae6e30d9 Drop pre-1.6 Go compatibility code
According to [1], Git-LFS requires "a reasonably modern version of Go".
Go 1.6 was released 3.5 years ago, time to move on.

[1]: https://github.com/git-lfs/git-lfs/wiki/Installation#source
2019-10-31 12:18:22 +03:00
Marat Radchenko
482260c7e3 Fix error strings to follow Go guidelines
Error strings should not be capitalized (unless beginning with proper nouns or acronyms) or end with punctuation:
https://github.com/golang/go/wiki/CodeReviewComments#error-strings
2019-10-22 17:33:49 +03:00
brian m. carlson
9580353dca subprocess: add a function to shell quote a single string
We currently have a function to shell quote a list of strings, but in
some cases we may want to just quote a single string.  To avoid the
complexity of having to create a bunch of temporaries and then index out
the result, create a function that shell quotes just a single string.
2018-09-14 22:46:17 +00:00
brian m. carlson
912891d48f subprocess: add functions to format shell commands
There are a small number of places where we'll want to pass data to the
shell.  Add a function which formats a command name and arguments into a
command that invokes "sh -c" with the appropriate args.  Additionally
add a form that quotes its arguments, and use this in the SSH code,
which wants to pass data to the shell.
2018-09-14 22:31:39 +00:00
brian m. carlson
54fc03da43 subprocess: don't escape shell command due to slash
Add the slash to the list of characters which don't require quoting for
the shell.  No POSIX-compatible shell requires escaping the slash, and
ignoring it for the purposes of escaping lets us write cleaner,
nicer-to-read trace output.

Don't do the same with the backslash, which while being the equivalent
on Windows, is handled specially by POSIX shells.
2018-09-14 22:28:28 +00:00
brian m. carlson
899168eb50 tools: move ShellQuote to subprocess
In a future commit, we'll be adding some additional shell-related
handling which logically belongs to the subprocess package.  To avoid an
import loop, move the ShellQuote function and its required variable from
the tools package to the subprocess package.  Update the only caller of
this function.

This commit contains no functional change.
2018-09-14 21:50:09 +00:00
rick olson
7d003a17c6 git: run 'config' from dir based on *Configuration 2017-10-25 19:46:36 -06:00
rick olson
1fe966ac10 subprocess: add helper for consistent trace messages 2017-10-25 19:33:16 -06:00
Lars Schneider
f06601cab5 git: add git[NoLFS]Buffered() to run a Git processes with buffered output
Replicate `lfs/gitscanner_cmd` in `subprocess/buffered_cmd` using
subprocess/cmd. In subsequent commits we will migrate all functions
users of `lfs/gitscanner_cmd` to `subprocess/buffered_cmd` and
afterwards remove `lfs/gitscanner_cmd`.
2017-08-22 19:34:29 +02:00
Brett Randall
d06e97b37d Removed Go 1.6-specific API changes introduced in the previous commit. This commit can be reverted as soon as Go >= 1.6 is required.
This commit copies-down some utility methods introduced as part of the API change in Go 1.6.  These changes are convenient to use here, since they auto-truncate stderr error output.

Revert this commit when moving to Go 1.6.
2016-06-30 12:05:30 +10:00
Brett Randall
77734205b8 Stop SimpleExec swallowing errors. Fixed #1183.
ExitError conditions now return a plain error with message like:

    Error running git [config --system filter.lfs.clean git-lfs clean -- %f]: 'error: could not lock config file /etc/gitconfig: Permission denied' 'exit status 255'

Also:

* Made Set/Unset Config commands return errors when they occur.
* Made install attribute set fail properly with an error message e.g. if permission-denied.  Previously this failed silently and reported success.

***NOTE*** this commit contains Go 1.6-specific APIs.  The following commit will remove those, and that following commit can be reverted when Go >= 1.6 is required.
2016-06-30 12:05:30 +10:00
Taylor Blau
4593d0a641 vendor: vendor dependencies in vendor/ using Glide
- script/vendor received an update in order to work with Glide
- import paths have been rewritten to work with GO15VENDOREXPERIMENT
2016-05-23 12:10:35 -06:00
Steve Streeting
ab53c53e72 Document that our package structure is not guaranteed to be stable 2016-05-18 11:43:42 +01:00
Steve Streeting
d27a09e50f Refactor execCommand and simpleExec into separate package 2016-03-08 16:48:07 +00:00