Skip to content

Commit 41559fa

Browse files
committed
fix(git): avoid signing commits when gpgsign is unset
1 parent 3a04a3d commit 41559fa

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎src-tauri/src/git/cli.rs‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2494,16 +2494,13 @@ impl GitOperationHandler for CliGitHandler {
24942494
&[1],
24952495
)
24962496
.ok()
2497-
.map(|value| value.trim().to_ascii_lowercase());
2498-
let has_signing_key =
2499-
Self::run_git(&["config", "--get", "user.signingkey"], Some(&repo_path))
2500-
.map(|value| !value.trim().is_empty())
2501-
.unwrap_or(false);
2497+
.map(|value| value.trim().to_ascii_lowercase())
2498+
.filter(|value| !value.is_empty());
25022499
let should_sign = match commit_gpgsign.as_deref() {
25032500
Some("false") | Some("0") | Some("no") | Some("off") => false,
25042501
Some("true") | Some("1") | Some("yes") | Some("on") => true,
25052502
Some(_) => true,
2506-
None => has_signing_key,
2503+
None => false,
25072504
};
25082505
if should_sign {
25092506
#[cfg(windows)]

‎src-tauri/tests/git.rs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,27 @@ fn commit_creates_entry_in_log() {
13391339
assert!(commits.iter().any(|c| c.message == "add b.txt"));
13401340
}
13411341

1342+
#[test]
1343+
fn commit_does_not_sign_when_gpgsign_is_unset() {
1344+
let dir = init_repo();
1345+
git(dir.path(), &["config", "--unset", "commit.gpgsign"]);
1346+
write_file(dir.path(), "unsigned.txt", "data");
1347+
git(dir.path(), &["add", "unsigned.txt"]);
1348+
1349+
handler()
1350+
.commit_changes(&CommitRequest {
1351+
repo_path: dir.path().to_str().unwrap().to_string(),
1352+
message: "commit without signing".to_string(),
1353+
amend: None,
1354+
})
1355+
.expect("commit_changes should not sign when commit.gpgsign is unset");
1356+
1357+
assert_eq!(
1358+
git_stdout(dir.path(), &["log", "-1", "--format=%s"]),
1359+
"commit without signing"
1360+
);
1361+
}
1362+
13421363
#[test]
13431364
fn commit_preserves_description_and_trailer_like_lines() {
13441365
let dir = init_repo();

0 commit comments

Comments
 (0)