>>>>>> 3. Evaluate:
>>>>>>
>>>>>> (let ((dir default-directory)
>>>>>> (env (cons "MAGIT_TRAMP_TEST=yes" process-environment)))
>>>>>> (with-temp-buffer
>>>>>> (setq default-directory dir)
>>>>>> (setq-local process-environment env)
>>>>>> (process-file "sh" nil t nil "-c"
>>>>>> "printf '%s' \"$MAGIT_TRAMP_TEST\"")
>>>>>> (buffer-string)))
> with-environment-variables would be the right thing to use.
>
> But OP claims Magit would be calling setq-local on process-environment
> at some point, which with-environment-variables clearly doesn't do.
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))))