Jonas Bernoulli <[email protected]> writes:

Hi Jonas,

> They misrepresented what Magit does.  It does this:
>
> (with-environment-variables (("GIT_INDEX_FILE" ,file))
>   ,@body)
>
> In full context:
>
> (defmacro magit-with-temp-index (tree arg &rest body)
>   (declare (indent 2) (debug (form form body)))
>   (let ((file (gensym "file")))
>     `(let ((magit--refresh-cache nil)
>            (,file (magit-convert-filename-for-git
>                    (make-temp-name
>                     (expand-file-name "index.magit." (magit-gitdir))))))
>        (unwind-protect
>            (magit-with-toplevel
>              (when-let* ((tree ,tree)
>                          (_(not (magit-git-success
>                                  "read-tree" ,arg tree
>                                  (concat "--index-output=" ,file)))))
>                (error "Cannot read tree %s" tree))
>              (with-environment-variables (("GIT_INDEX_FILE" ,file))
>                ,@body))
>          (ignore-errors
>            (delete-file (concat (file-remote-p default-directory) ,file)))))))
>
> (defun magit-commit-worktree (message &optional arg &rest other-parents)
>   (magit-with-temp-index "HEAD" arg
>     (and (magit-update-files (magit-unstaged-files))
>          (apply #'magit-commit-tree message nil "HEAD" other-parents))))

I don't know magit at all, so it might be dumb what I'm saying. However,
there is

--8<---------------cut here---------------start------------->8---
(defmacro magit--with-temp-process-buffer (&rest body)
  "Like `with-temp-buffer', but always propagate `process-environment'.
When that var is buffer-local in the calling buffer, it is not
propagated by `with-temp-buffer', so we explicitly ensure that
happens, so that processes will be invoked consistently.  BODY is
as for that macro."
  (declare (indent 0) (debug (body)))
  (let ((p (gensym)))
    `(let ((,p process-environment))
       (with-temp-buffer
         (setq-local process-environment ,p)
         ,@body))))
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.

Reply via email to