From 2b87a11125f988a9f67ee63eeaa3682bc841d9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= <34611103+d4ilyrun@users.noreply.github.com> Date: Mon, 6 May 2024 08:17:53 +0200 Subject: [PATCH] git: add realName inside From field We currently have no way of specifying the sender's name inside the From field, making a patch sent through `git send-email` appear as coming from "xxx@domain.com". In this commit we make this field follow the standard realName format. --- modules/programs/git.nix | 4 ++-- tests/modules/programs/git/git-with-email-expected.conf | 4 ++-- tests/modules/programs/git/git-with-email.nix | 4 ++-- tests/modules/programs/git/git-with-msmtp-expected.conf | 4 ++-- tests/modules/programs/git/git-with-msmtp.nix | 5 +++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 53728060a..3061feff7 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -392,7 +392,7 @@ in { nameValuePair "sendemail.${name}" (if account.msmtp.enable then { smtpServer = "${pkgs.msmtp}/bin/msmtp"; envelopeSender = "auto"; - from = address; + from = "${realName} <${address}>"; } else { smtpEncryption = if smtp.tls.enable then @@ -407,7 +407,7 @@ in { mkIf smtp.tls.enable (toString smtp.tls.certificatesFile); smtpServer = smtp.host; smtpUser = userName; - from = address; + from = "${realName} <${address}>"; } // optionalAttrs (smtp.port != null) { smtpServerPort = smtp.port; }); diff --git a/tests/modules/programs/git/git-with-email-expected.conf b/tests/modules/programs/git/git-with-email-expected.conf index c34ab1d79..fa027422f 100644 --- a/tests/modules/programs/git/git-with-email-expected.conf +++ b/tests/modules/programs/git/git-with-email-expected.conf @@ -1,12 +1,12 @@ [sendemail "hm-account"] - from = "hm@example.org" + from = "H. M. Test Jr. " smtpEncryption = "tls" smtpServer = "smtp.example.org" smtpSslCertPath = "/etc/test/certificates.crt" smtpUser = "home.manager.jr" [sendemail "hm@example.com"] - from = "hm@example.com" + from = "H. M. Test " smtpEncryption = "ssl" smtpServer = "smtp.example.com" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" diff --git a/tests/modules/programs/git/git-with-email.nix b/tests/modules/programs/git/git-with-email.nix index ec18ecb92..0999eaa87 100644 --- a/tests/modules/programs/git/git-with-email.nix +++ b/tests/modules/programs/git/git-with-email.nix @@ -33,8 +33,8 @@ with lib; ./git-with-email-expected.conf } - assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" - assertGitConfig "sendemail.hm-account.from" "hm@example.org" + assertGitConfig "sendemail.hm@example.com.from" "H. M. Test " + assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. " ''; }; } diff --git a/tests/modules/programs/git/git-with-msmtp-expected.conf b/tests/modules/programs/git/git-with-msmtp-expected.conf index 1f2c7b794..8cd5d86f0 100644 --- a/tests/modules/programs/git/git-with-msmtp-expected.conf +++ b/tests/modules/programs/git/git-with-msmtp-expected.conf @@ -1,5 +1,5 @@ [sendemail "hm-account"] - from = "hm@example.org" + from = "H. M. Test Jr. " smtpEncryption = "tls" smtpServer = "smtp.example.org" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" @@ -7,7 +7,7 @@ [sendemail "hm@example.com"] envelopeSender = "auto" - from = "hm@example.com" + from = "H. M. Test " smtpServer = "@msmtp@/bin/msmtp" [user] diff --git a/tests/modules/programs/git/git-with-msmtp.nix b/tests/modules/programs/git/git-with-msmtp.nix index dc6ba465e..80e082c97 100644 --- a/tests/modules/programs/git/git-with-msmtp.nix +++ b/tests/modules/programs/git/git-with-msmtp.nix @@ -7,6 +7,7 @@ with lib; config = { accounts.email.accounts."hm@example.com".msmtp.enable = true; + programs.git = { enable = true; package = pkgs.gitMinimal; @@ -33,8 +34,8 @@ with lib; assertFileContent home-files/.config/git/config \ ${./git-with-msmtp-expected.conf} - assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" - assertGitConfig "sendemail.hm-account.from" "hm@example.org" + assertGitConfig "sendemail.hm@example.com.from" "H. M. Test " + assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. " assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp" assertGitConfig "sendemail.hm@example.com.envelopeSender" "auto" '';