Skip to content

Commit

Permalink
fix(directory variables): use hack call instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sbougerel committed Apr 27, 2024
1 parent a017df2 commit aba180f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions autosync-magit-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

(ert-deftest autosync-magit-push--ahead ()
(cl-letf (((symbol-value 'call-recorder) nil)
((symbol-function 'cd) #'ignore)
((symbol-function 'hack-dir-local-variables-non-file-buffer) #'ignore)
((symbol-function 'magit-toplevel) (always-return "/dir"))
((symbol-function 'magit-run-git-async) (record-calls-and-return nil))
((symbol-function 'magit-rev-eq) (always-nil))
Expand All @@ -81,7 +81,7 @@

(ert-deftest autosync-magit-push--no-changes ()
(cl-letf (((symbol-value 'call-recorder) nil)
((symbol-function 'cd) #'ignore)
((symbol-function 'hack-dir-local-variables-non-file-buffer) #'ignore)
((symbol-function 'magit-toplevel) (always-return "/dir"))
((symbol-function 'magit-run-git-async) (record-calls-and-return nil))
((symbol-function 'magit-rev-eq) (always-return t))
Expand All @@ -100,7 +100,7 @@
:last-pull (seconds-to-time 0)
:next-push (seconds-to-time 0)
:timer 0))))
((symbol-function 'cd) #'ignore)
((symbol-function 'hack-dir-local-variables-non-file-buffer) #'ignore)
((symbol-function 'magit-toplevel) (always-return "/dir"))
((symbol-function 'magit-run-git-async) (record-calls-and-return nil))
((symbol-function 'magit-run-git) (record-calls-and-return nil))
Expand All @@ -126,7 +126,7 @@
:last-pull (seconds-to-time 0)
:next-push (seconds-to-time 0)
:timer 0))))
((symbol-function 'cd) #'ignore)
((symbol-function 'hack-dir-local-variables-non-file-buffer) #'ignore)
((symbol-function 'magit-toplevel) (always-return "/dir"))
((symbol-function 'magit-run-git-async) (record-calls-and-return nil))
((symbol-function 'magit-run-git) (record-calls-and-return nil))
Expand Down
10 changes: 7 additions & 3 deletions autosync-magit.el
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,14 @@ instead.")
(defmacro autosync-magit--with-repo (repo_dir &rest body)
"Run BODY in a temporary buffer where current directory is REPO_DIR.
Since file-visiting buffer may be killed before this function runs,
we don't rely on them."
Avoid relying on file-visiting buffers that may be killed before body runs.
Ensure directory local variables are loaded."
(declare (indent 1) (debug t))
`(with-temp-buffer (cd ,repo_dir) ,@body))
`(with-temp-buffer
(let ((default-directory ,repo_dir)
(enable-dir-local-variables t))
(hack-dir-local-variables-non-file-buffer)
,@body)))

;;;###autoload
(defun autosync-magit-pull (repo_dir)
Expand Down

0 comments on commit aba180f

Please sign in to comment.