Skip to content

Commit

Permalink
git: add realName inside From field
Browse files Browse the repository at this point in the history
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 "[email protected]".

In this commit we make this field follow the standard

    realName <email>

format.
  • Loading branch information
d4ilyrun authored May 6, 2024
1 parent 3dfe05a commit 2b87a11
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/programs/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
});
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-email-expected.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[sendemail "hm-account"]
from = "[email protected]"
from = "H. M. Test Jr. <[email protected]>"
smtpEncryption = "tls"
smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/test/certificates.crt"
smtpUser = "home.manager.jr"

[sendemail "[email protected]"]
from = "[email protected]"
from = "H. M. Test <[email protected]>"
smtpEncryption = "ssl"
smtpServer = "smtp.example.com"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"
Expand Down
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-email.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ with lib;
./git-with-email-expected.conf
}
assertGitConfig "[email protected]" "[email protected]"
assertGitConfig "sendemail.hm-account.from" "[email protected]"
assertGitConfig "[email protected]" "H. M. Test <[email protected]>"
assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <[email protected]>"
'';
};
}
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git-with-msmtp-expected.conf
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[sendemail "hm-account"]
from = "[email protected]"
from = "H. M. Test Jr. <[email protected]>"
smtpEncryption = "tls"
smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"
smtpUser = "home.manager.jr"

[sendemail "[email protected]"]
envelopeSender = "auto"
from = "[email protected]"
from = "H. M. Test <[email protected]>"
smtpServer = "@msmtp@/bin/msmtp"

[user]
Expand Down
5 changes: 3 additions & 2 deletions tests/modules/programs/git/git-with-msmtp.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ with lib;

config = {
accounts.email.accounts."[email protected]".msmtp.enable = true;

programs.git = {
enable = true;
package = pkgs.gitMinimal;
Expand All @@ -33,8 +34,8 @@ with lib;
assertFileContent home-files/.config/git/config \
${./git-with-msmtp-expected.conf}
assertGitConfig "[email protected]" "[email protected]"
assertGitConfig "sendemail.hm-account.from" "[email protected]"
assertGitConfig "[email protected]" "H. M. Test <[email protected]>"
assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <[email protected]>"
assertGitConfig "[email protected]" "${pkgs.msmtp}/bin/msmtp"
assertGitConfig "[email protected]" "auto"
'';
Expand Down

0 comments on commit 2b87a11

Please sign in to comment.