Skip to content

fix: use bash -c to get interpretation of tilde and env vars in path #5756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions crates/gitbutler-repo/src/repository_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,12 @@ impl RepositoryExt for git2::Repository {
gpg_program = "ssh-keygen".to_string();
}

let mut cmd = std::process::Command::new(gpg_program);
cmd.args(["-Y", "sign", "-n", "git", "-f"]);
let mut cmd_string = format!("{} -Y sign -n git -f ", gpg_program);

#[cfg(windows)]
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
let buffer_file_to_sign_path_str = buffer_file_to_sign_path
.to_str()
.ok_or_else(|| anyhow::anyhow!("Failed to convert path to string"))?
.to_string();

let output;
// support literal ssh key
Expand All @@ -425,23 +426,40 @@ impl RepositoryExt for git2::Repository {

let key_file_path = key_storage.into_temp_path();

cmd.arg(&key_file_path);
cmd.arg("-U");
cmd.arg(&buffer_file_to_sign_path);
cmd.stderr(Stdio::piped());
cmd.stdout(Stdio::piped());
cmd.stdin(Stdio::null());
let args = format!(
"{} -U {}",
key_file_path.to_string_lossy(),
buffer_file_to_sign_path.to_string_lossy()
);
cmd_string += &args;

let mut signing_cmd: std::process::Command =
gix::command::prepare(cmd_string).with_shell().into();

#[cfg(windows)]
signing_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW

let child = cmd.spawn()?;
signing_cmd.stderr(Stdio::piped());
signing_cmd.stdout(Stdio::piped());
signing_cmd.stdin(Stdio::null());

let child = signing_cmd.spawn()?;
output = child.wait_with_output()?;
} else {
cmd.arg(signing_key);
cmd.arg(&buffer_file_to_sign_path);
cmd.stderr(Stdio::piped());
cmd.stdout(Stdio::piped());
cmd.stdin(Stdio::null());
let args = format!("{} {}", signing_key, buffer_file_to_sign_path_str);
cmd_string += &args;

let mut signing_cmd: std::process::Command =
gix::command::prepare(cmd_string).with_shell().into();

#[cfg(windows)]
signing_cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW

signing_cmd.stderr(Stdio::piped());
signing_cmd.stdout(Stdio::piped());
signing_cmd.stdin(Stdio::null());

let child = cmd.spawn()?;
let child = signing_cmd.spawn()?;
output = child.wait_with_output()?;
}

Expand Down
Loading