1

I'm just getting started with git send-mail for a sourcehut project, so far so good.

My current .gitconfig looks like this:

[user]
    email = johndoe@host.com
    name = John Doe
    signingkey = <mysignkey>
[commit]
    gpgsign = true
[format]
    subjectPrefix = [PATCH]
[sendemail]
    smtpserver = smtp.johndoe.com
    smtpuser = johndoe@host.com
    smtpencryption = ssl
    smtpserverport = 465
    smtppass = my-password-in-clear-text

Is there a way to set smtppass with a pass + sed instead of having it in clear text?

I'm using pass, usually I'm setting it up with a passcmd pass show host.com/johndoe.com | sed -n '3p but I don't know how I can do that in .gitconfig.

1 Answers1

1

I do not think you can directly use a pass command in your .gitconfig file. It is just a plain text file, and there's no way to execute shell commands within it.

One possible workaround is to create a script that retrieves the password from pass, and then use that script in the smtppass option.

But git send-mail would explain the configuration [sendemail].smtppass to be the password, not a command to retrieve it.

Check if using a git credential helper would help, assuming GCM is installed:

git config --global credential.helper manager

(Your executable git-credential-manager, or git-credential-manager-core for older Git version, must be in your $PATH/%PATH%)

printf "host=smtp.johndoe.com:465\nusername=johndoe@host.com\nprotocol=smtp" | git-credential-manager store $(pass show host.com/johndoe.com | sed -n '3p')

If GCM is not available, you can, as suggested in your thread, use a custom helper:

[credential "smtp://smtp.johndoe.com:465"]
    helper = "!f() { echo username=johndoe@host.com; echo \"password=$(pass show xenrox/mail.xenrox.net/thorben | sed -n '3p')\"; }; f"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the response! Unfortunately it doesn't really accept the value from a bash script `fatal: bad config line 3 in file //get-smpt-pass` for now the only workaround that I could find is through emacs `password-store`. I will put an update tomorrow if I find a better solution. – Thanos_Apollo Apr 27 '23 at 11:54
  • @Thanos_Apollo OK, I have updated the answer to use the Emacs password store. – VonC Apr 27 '23 at 12:08
  • I don't think the above solution is working. Even having $(echo "password") is not accepted, so I believe we can't utilize any solution that includes this format. What I'm doing with `password-store` is having a function like ` (insert (password-store-get-field "mail.com/johndoe.com" "smtp"))` bind it to a key and then just insert it whenever I'm asked for it. I also asked sr.ht-discuss here https://lists.sr.ht/~sircmpwn/sr.ht-discuss/%3C87mt2tmsjp.fsf%40thanosapollo.com%3E according to their replies(as of now) I should find a way through using git-credentials. – Thanos_Apollo Apr 27 '23 at 13:04
  • @Thanos_Apollo True, I mention the [GCM (Git Credential Manager) here](https://stackoverflow.com/a/68768432/6309). You can use it to store/retrieve credentials, as [illustrated here](https://stackoverflow.com/a/74515709/6309). – VonC Apr 27 '23 at 13:36
  • @Thanos_Apollo I have rewritten the answer to use GCM. – VonC Apr 27 '23 at 13:49
  • I fixed my issue using xenrox [gitconfig](https://paste.xenrox.net/~xenrox/49cefdf456533aeadfe176f237632f2aa0a5c7fb) which is almost the same as your current reply. Thank you for your help! – Thanos_Apollo Apr 27 '23 at 14:29