2018-05-28 Collaborating with non-Git-users - Emacs support

In the previous part, I showed how I can make Git add information about the commit in every file I want it to in such a way that it is updated every time I Git-archive the project.

Actually, I have written an Elisp function to do this for me; it prepares a zip file with git archive and then writes a boilerplate email in mu4e, with the recipients’ addresses, attachment and a minimal body already in place. Here it is (with the personal data stripped down). (If you don’t use mu4e contexts, you can safely delete all parts relating to them, of course. I just didn’t want this command to ask me for context every time.)

(defvar auto-git-archive-repo-dir "~/repo/directory/")

(defun git-archive-and-prepare-email ()
  "Prepare a message to the rest of people with an update."
  (interactive)
  (let ((default-directory auto-git-archive-repo-dir)
	(mu4e-compose-context-policy nil)
	(mu4e-context nil))
    (shell-command "git archive -o current-version.zip master")
    (mu4e-context-switch nil "context")
    (gnus-dired-attach (list (concat auto-git-archive-repo-dir "current-version.zip")))
    (message-goto-to)
    (insert "recipient1 <rec1@example.com>, recipient2 <rec2@example.com>")
    (message-goto-subject)
    (insert "Project update")
    (message-goto-body)
    (insert "Dear all,\n\nI enclose the current state of our project.\n\nBest,\n")
    (previous-line 2)
    (end-of-line)))

I can just now run this command and press C-c C-c (or add some text to the email first). Again, Elisp’s ability to write programs mimicking the actions of a human editor turns out to be a great thing.

Another place Emacs can help me with my workflow is entering author information in Magit. I could probably somehow plug in the Magit’s pop-up menu, but instead I went for a simpler version, which is the following hydra:

(defhydra hydra-git-project (:exit t)
  "Simple hydra for the Git project"
  ("m" (insert "Marcin Borkowski <mbork@mbork.pl>") "mbork")
  ("1" (insert "Collaborator1 <coll1@example.com>") "col1")
  ("2" (insert "Collaborator2 <coll2@example.com>") "col2"))

(global-set-key (kbd "s-b") 'hydra-git-project/body)

I can now just press =A s-b before committing to display the menu with the collaborator list and select the right one with one keystroke.

In the next and final part I am going to describe how I configured a Git hook to prevent me from accidentally committing a wrong thing or the right thing with a wrong author. Stay tuned!

CategoryEnglish, CategoryBlog, CategoryGit, CategoryEmacs