fix GIT_SSH_COMMAND -n parameter

It was being passed to sh, not to the command, oops. Noticed because it
broke the test suite on OSX, where sh -n silently does nothing. Would
also break on Linux when eg posh was being used as the shell; bash
ignores the -n.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2017-03-20 14:23:19 -04:00
parent df2639218a
commit c8a6be7eef
No known key found for this signature in database
GPG key ID: C910D9222512E3C7

View file

@ -34,7 +34,10 @@ type SshCommand = String
-- | Checks for GIT_SSH and GIT_SSH_COMMAND and if set, returns
-- a command and parameters to run to ssh.
gitSsh :: SshHost -> Maybe SshPort -> SshCommand -> IO (Maybe (FilePath, [CommandParam]))
gitSsh host mp cmd = do
gitSsh host mp cmd = gitSsh' host mp cmd []
gitSsh' :: SshHost -> Maybe SshPort -> SshCommand -> [CommandParam] -> IO (Maybe (FilePath, [CommandParam]))
gitSsh' host mp cmd extrasshparams = do
gsc <- getEnv gitSshCommandEnv
case gsc of
Just c
@ -42,24 +45,27 @@ gitSsh host mp cmd = do
-- when it contains spaces; otherwise it's
-- treated the same as GIT_SSH
| any isSpace c -> ret "sh"
[ [ Param "-c"
, Param (shellcmd c gitps)
]
[ Param "-c"
, Param (shellcmd c sshps)
]
| otherwise -> ret c [gitps]
| otherwise -> ret c sshps
Nothing -> do
gs <- getEnv gitSshEnv
case gs of
Just c -> ret c [gitps]
Just c -> ret c sshps
Nothing -> return Nothing
where
ret c ll = return $ Just (c, concat ll)
ret c l = return $ Just (c, l)
-- git passes exactly these parameters to the command
-- Git passes exactly these parameters to the ssh command.
gitps = map Param $ case mp of
Nothing -> [host, cmd]
Just p -> [host, "-p", show p, cmd]
-- Passing any extra parameters to the ssh command may
-- break some commands.
sshps = extrasshparams ++ gitps
-- The shell command to run with sh -c is constructed
-- this way, rather than using "$@" because there could be some
-- unwanted parameters passed to the command, and this way they