                     (file-notify-add-watch head '(change) 'handle-git-state-change))))))))
 
   (defun reap-git-head-watchers ()
-    (let* ((buffer-default-dirs-sans-current
-            (seq-uniq
-             (mapcar
-              (lambda (buf) (with-current-buffer buf (expand-file-name default-directory)))
-              (seq-filter
-               (lambda (buf)
-                 (not (or (string-prefix-p " " (buffer-name buf))
-                          (equal buf (current-buffer)))))
-               (apply 'append
-                      (mapcar
-                       'buffer-list
-                       (seq-filter
-                        (lambda (frame) (not (frame-parent frame)))
-                        (frame-list))))))))
-           (git-heads-to-delete
-            (seq-filter
-             (lambda (git-head)
-               (let ((vc-root (apply 'file-name-concat "/" (seq-subseq (split-string git-head "/") 0 -3))))
-                 (not (seq-some (apply-partially 'string-prefix-p vc-root) buffer-default-dirs-sans-current))))
-             (mapcar 'car watched-git-heads))))
+    (when-let* ((buffer-default-dirs-sans-current
+                 (seq-uniq
+                  (mapcar
+                   (lambda (buf) (with-current-buffer buf (expand-file-name default-directory)))
+                   (seq-filter
+                    (lambda (buf)
+                      (not (or (string-prefix-p " " (buffer-name buf))
+                               (equal buf (current-buffer)))))
+                    (apply 'append
+                           (mapcar
+                            'buffer-list
+                            (seq-filter
+                             (lambda (frame) (not (frame-parent frame)))
+                             (frame-list))))))))
+                (git-heads-to-delete
+                 (seq-filter
+                  (lambda (git-head)
+                    (let ((vc-root (apply 'file-name-concat "/" (seq-subseq (split-string git-head "/") 0 -3))))
+                      (not (seq-some (apply-partially 'string-prefix-p vc-root) buffer-default-dirs-sans-current))))
+                  (mapcar 'car watched-git-heads))))
 
       (dolist (git-head git-heads-to-delete)
         (let ((watcher (assoc-default git-head watched-git-heads)))

          (vc-refresh-state))))))

  (defun handle-git-state-change (event)
    "Callback to `file-notify-add-watch'.

If EVENT is a file system notification event.  If EVENT is a change event,

See `file-notify-add-watch' for more details."
    (pcase-let ((`(,desc ,action ,file ,@_) event))

                 (when (not (string-prefix-p " " (buffer-name buf)))
                   (with-current-buffer buf
                     (when (string-prefix-p vc-root (expand-file-name default-directory))
                       (refresh-buffer-base-on-git-state))))))))))))

  (defun watch-git-head ()
    (let ((file (buffer-file-name)))
