How to send a patch to a mailing list using git imap-send with Gmail Two Factor Authentication (2FA) enabled
While most open source projects accept contributions through a pull request, a lot of projects accept contributions through patches mailed them to their mailing list. In this post, I'll show how to send a patch using git’s format-patch.
First commit the changes. Lets call the commit message “fix use after free”, a common bug in C, where one attempts to use a pointer that was just freed.
git comit -m “fix use after free”
Next, create an mbox compatible patch using git format-patch. If no name is specified for the patch, git creates one based on the commit message.
git format-patch master 0001-fix-use-after-free.patch
You can verify the contents of the patch to ensure your changes
cat 0001-fix-use-after-free.patch From 2583f0a9a9cf1369ef4b7e29623776aaa8795db0 Mon Sep 17 00:00:00 2001 From: Gmail User <[email protected]> Date: Sun, 9 Jul 2017 10:05:47 +0530 Subject: [PATCH] fix use after free --- grub-core/normal/crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grub-core/normal/crypto.c b/grub-core/normal/crypto.c index 2bfd67c..e6d345f 100644 --- a/grub-core/normal/crypto.c +++ b/grub-core/normal/crypto.c @@ -147,8 +147,8 @@ read_crypto_list (const char *prefix) if (! cur->modname) { grub_errno = GRUB_ERR_NONE; - grub_free (cur); grub_free (cur->name); + grub_free (cur); continue; } cur->next = crypto_specs; -- 2.9.4
Generate app-specific password for Gmail (if 2FA is enabled)
If you have 2FA enabled for Gmail, then you would need to generate an app-specific password instead of your usual password. Click here to generate an app specific password to use with git. For detailed steps on how to generate the password, see Google's help page.
Mailing the patch
Next, we need to configure the imap section for git, so that we can send our patch to Gmail's Drafts folder. Create a gitconfig file in your home folder, ~/.gitconfig and enter the following in the imap section. The password would be the 16 digit key generated in the previous step.
[imap] folder = "[Gmail]/Drafts" host = imaps://imap.gmail.com user = [email protected] pass = abcdefghijklmnop
Normally I wouldn't recommend storing your passwords on plaintext file. If you're paranoid like me, then remove the pass line from the .gitconfig file. This would prompt you to enter the password every time you want to send a patch. This could become particularly painstaking when you want to push a lot of commits and need to enter the password every time. In that case, you can consider using gitcredentials which has options of storing it securely.
Finally, when you're all set, mail the patch using imap-send
cat *.patch | git imap-send
That's it! Login to Gmail and check your Drafts folder. Your email would be sitting there. Make any changes if needed, add the mailing list in the "To" field and hit send. You have now successfully sent a patch and help made the opensource world better. Happy hacking!












