askpass: Skip the GPG wrapper when GPG is missing (#66143)

A missing binary shouldn't warn.

Release Notes:

- N/A
This commit is contained in:
Lukas Wirth
2026-10-26 09:53:33 +00:00
committed by GitHub
parent 08104dc649
commit e645f02245
+8 -5
View File
@@ -297,10 +297,11 @@ impl PasswordProxy {
#[cfg(not(target_os = "windows"))]
let (gpg_wrapper_script_path, gpg_wrapper_script) =
match generate_gpg_wrapper_script(askpass_program, &askpass_socket_path) {
Ok(script) => (
Ok(Some(script)) => (
Some(temp_dir.path().join(GPG_WRAPPER_SCRIPT_NAME)),
Some(script),
),
Ok(None) => (None, None),
Err(err) => {
log::warn!("could not create gpg askpass wrapper: {err:#}");
(None, None)
@@ -505,9 +506,11 @@ fn generate_askpass_script(
fn generate_gpg_wrapper_script(
askpass_program: &std::path::Path,
askpass_socket: &std::path::Path,
) -> Result<String> {
) -> Result<Option<String>> {
let shell_kind = ShellKind::Posix;
let gpg_program = find_gpg_program().context("could not find a gpg binary on PATH")?;
let Some(gpg_program) = find_gpg_program() else {
return Ok(None);
};
let gpg_program = gpg_program
.to_str()
.context("gpg program is on a non-utf8 path")?;
@@ -550,7 +553,7 @@ fn generate_gpg_wrapper_script(
// from stdout, so we buffer stdin to replay it into each attempt and buffer
// each attempt's output, forwarding it only if it succeeds. The
// passphrase goes to fd 3 via a pipe.
Ok(format!(
Ok(Some(format!(
r#"#!/bin/sh
for arg in "$@"; do
case "$arg" in
@@ -603,7 +606,7 @@ passphrase=$(printf '%s\0' {prompt} | {askpass_program} --askpass={askpass_socke
printf '%s\n' "$passphrase" |
{gpg_program} --pinentry-mode loopback --passphrase-fd 3 "$@" 3<&0 < "$payload"
"#,
))
)))
}
/// Finds the real `gpg` (or `gpg2`) executable on `PATH`.