Force use of scp rather than sftp when possible

OpenSSH has deprecated its use of scp/rcp protocol in favor of SFTP,
which the embedded Apache mina-sshd in widely-deployed Gerrit
versions does not yet support. The default officially changed in
OpenSSH 9.0 (some distributions, such as Fedora and CentOS, switched
their default behavior to this as early as OpenSSH 8.7 or 8.8),
leading to a ``subsystem request failed on channel 0`` error during
commit-msg hook retrieval. Now git-review will attempt to detect
whether scp's -O option is available to force use of the legacy
scp/rcp protocol, and apply it if so.

Change-Id: Ib64c03c3e12a3a8390e38f6ca9393db3b3c2a9e3
This commit is contained in:
Jonathan Rosser 2022-01-04 17:42:03 +00:00 committed by Jeremy Stanley
parent 25c2d3fe96
commit 5bfaa4a6f3
2 changed files with 23 additions and 0 deletions

View File

@ -373,9 +373,17 @@ def set_hooks_commit_msg(remote, target_file):
userhost = hostname
# OS independent target file
scp_target_file = target_file.replace(os.sep, "/")
# Get scp options
scp_out = run_command("scp")
scp_opts = scp_out[scp_out.index("[") + 2:scp_out.index("]")]
cmd = ["scp", userhost + ":hooks/commit-msg", scp_target_file]
if port is not None:
cmd.insert(1, "-P%s" % port)
# Force scp protocol if the -O option is available
if "O" in scp_opts:
cmd.insert(1, "-O")
if VERBOSE:
hook_url = 'scp://%s%s/hooks/commit-msg' \

View File

@ -0,0 +1,15 @@
---
fixes:
- |
OpenSSH has deprecated its use of scp/rcp protocol in favor of
SFTP, which the embedded Apache mina-sshd in widely-deployed
Gerrit versions does not yet support. The default officially
changed in OpenSSH 9.0 (some distributions, such as Fedora and
CentOS, switched their default behavior to this as early as
OpenSSH 8.7 or 8.8), leading to a ``subsystem request failed on
channel 0`` error during commit-msg hook retrieval. Now
git-review will attempt to detect whether scp's -O option is
available to force use of the legacy scp/rcp protocol, and apply
it if so. Future git-review versions may change the fallback
behavior once an SFTP subsystem is implemented and available for
a new Gerrit release.