Skip to content

Commit 7646075

Browse files
committed
tq: pass custom transfer adapter args to the shell
When a custom transfer adapter is specified in the configuration, it is not possible to specify multiple arguments to the process, because only the last value of the lfs.customtransfer.*.args option is read and the value is not split. To make things easier and more flexible, concatenate the path (after quoting) and the arguments and pass them to the shell. Update the documentation to reflect this change. Update the test custom transfer adapter to parse its arguments (which are otherwise ignored) and mention them to standard error. Make the test check that the arguments are parsed as the shell would expect them to be.
1 parent 9580353 commit 7646075

5 files changed

+16
-4
lines changed

docs/custom-transfers.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ A custom transfer process is defined under a settings group called
5656

5757
If the custom transfer process requires any arguments, these can be provided
5858
here. Typically you would only need this if your process was multi-purpose or
59-
particularly flexible, most of the time you won't need it.
59+
particularly flexible, most of the time you won't need it. Note that this
60+
string will be expanded by the shell.
6061

6162
* `lfs.customtransfer.<name>.concurrent`
6263

docs/man/git-lfs-config.5.ronn

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ be scoped inside the configuration for a remote.
128128
* `lfs.customtransfer.<name>.args`
129129

130130
If the custom transfer process requires any arguments, these can be provided
131-
here.
131+
here. This string will be expanded by the shell.
132132

133133
* `lfs.customtransfer.<name>.concurrent`
134134

t/cmd/lfstest-standalonecustomadapter.go

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func main() {
2828
os.Exit(1)
2929
}
3030

31+
for _, arg := range os.Args {
32+
writeToStderr(fmt.Sprintf("Saw argument %q\n", arg), errWriter)
33+
}
34+
3135
for scanner.Scan() {
3236
line := scanner.Text()
3337
var req request

t/t-custom-transfers.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ begin_test "custom-transfer-wrong-path"
2929
# use PIPESTATUS otherwise we get exit code from tee
3030
res=${PIPESTATUS[0]}
3131
grep "xfer: adapter \"testcustom\" Begin()" pushcustom.log
32-
grep "Failed to start custom transfer command" pushcustom.log
32+
grep "xfer: Aborting worker process" pushcustom.log
3333
if [ "$res" = "0" ]; then
3434
echo "Push should have failed because of an incorrect custom transfer path."
3535
exit 1
@@ -123,6 +123,7 @@ begin_test "custom-transfer-standalone"
123123

124124
# set up custom transfer adapter to use a specific transfer agent
125125
git config lfs.customtransfer.testcustom.path lfstest-standalonecustomadapter
126+
git config lfs.customtransfer.testcustom.args "--arg1 '--arg2 --arg3' --arg4"
126127
git config lfs.customtransfer.testcustom.concurrent false
127128
git config lfs.standalonetransferagent testcustom
128129
export TEST_STANDALONE_BACKUP_PATH="$(pwd)/test-custom-transfer-standalone-backup"
@@ -187,6 +188,11 @@ begin_test "custom-transfer-standalone"
187188

188189
grep "Terminating test custom adapter gracefully" fetchcustom.log
189190

191+
# Test argument parsing.
192+
grep 'Saw argument "--arg1"' fetchcustom.log
193+
grep 'Saw argument "--arg2 --arg3"' fetchcustom.log
194+
grep 'Saw argument "--arg4"' fetchcustom.log
195+
190196
objectlist=`find .git/lfs/objects -type f`
191197
[ "$(echo "$objectlist" | wc -l)" -eq 12 ]
192198
)

tq/custom.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func (a *customAdapter) WorkerStarting(workerNum int) (interface{}, error) {
128128
// Start a process per worker
129129
// If concurrent = false we have already dialled back workers to 1
130130
a.Trace("xfer: starting up custom transfer process %q for worker %d", a.name, workerNum)
131-
cmd := subprocess.ExecCommand(a.path, a.args)
131+
cmdName, cmdArgs := subprocess.FormatForShell(subprocess.ShellQuoteSingle(a.path), a.args)
132+
cmd := subprocess.ExecCommand(cmdName, cmdArgs...)
132133
outp, err := cmd.StdoutPipe()
133134
if err != nil {
134135
return nil, fmt.Errorf("Failed to get stdout for custom transfer command %q remote: %v", a.path, err)

0 commit comments

Comments
 (0)