Last month, I wrote about how I keep my two main machines in sync using git and how, after doing a git pull, I use a bit of Elisp to automate the reverting of my open buffers. After automating the reversion of buffers, I noticed that pulling all my repositories was also a pain. I had been just pulling the repository that I was going to use but that meant it was easy to forget which repositories were up to date and get things out of sync.
I decided to write a quick script to pull all repositories at once. That way I could just run the script when I began work on one of the computers and be sure that everything was up to date. Here's the
#! /bin/bash # -*- mode: sh -*- REPOS="/Users/jcs/org /Users/jcs/medical /Users/jcs/tax /Users/jcs/.emacs.d" for r in $REPOS do cd $r pwd echo "=========================" git pull echo done
There's nothing exciting here, of course. Most of the script is involved with outputting information as to what repository is being pulled.
pull-repos script is already a big time saver but to really automate things I made it callable from Emacs and folded in the
(defun sync-repos () "Pull from git repos and then revert all buffers." (interactive) (switch-to-buffer "*SYNC*") (goto-char (point-min)) (shell-command "/Users/jcs/bin/pull-repos" "*SYNC*") (revert-all-buffers) (end-of-buffer) (insert (format-time-string "%Y-%m-%d %T\n")) (insert "Buffers reverted"))
Now I just call
sync-repos and all my repositories are updated and all my buffers are reverted. One step when I first start using a machine: perfect.