Fix problems with org-attach-git, failed tests
Ref. mail "[O] git-annex-related org-attach tests failing on master" https://lists.gnu.org/archive/html/emacs-orgmode/2019-09/msg00030.html * lisp/org-attach-git.el (org-attach-git-commit): Add optional argument to function contract to make it work with `org-attach-after-change-hook'. Even though that argument is not used in the actual code (due to legacy functionality). * testing/lisp/test-org-attach.el (test-org-attach/dired-attach-to-next-best-subtree/1) (test-org-attach/dired-attach-to-next-best-subtree/2): Modify tests to also work if user has git-annex installed * testing/lisp/test-org-attach-git.el (test-org-attach-git/use-annex): Correct errors from previous commit, where git-annex was refactored out from org-attach into it's separate module.
This commit is contained in:
parent
f2f646b6c9
commit
930a1bcfc5
|
@ -23,10 +23,9 @@
|
|||
|
||||
;;; Commentary:
|
||||
|
||||
;; An extention to org-attach. If the attachment-directory to an
|
||||
;; outline node (using either DIR or ID) is initialized as a Git
|
||||
;; repository, then org-attach-git will automatically commit changes
|
||||
;; when it sees them.
|
||||
;; An extention to org-attach. If `org-attach-id-dir' is initialized
|
||||
;; as a Git repository, then org-attach-git will automatically commit
|
||||
;; changes when it sees them. Requires git-annex.
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
@ -81,9 +80,12 @@ Signals an error if the file content is not available and it was not retrieved."
|
|||
(message "Running git annex get \"%s\"." path-relative)
|
||||
(call-process "git" nil nil nil "annex" "get" path-relative)))))
|
||||
|
||||
(defun org-attach-git-commit ()
|
||||
(defun org-attach-git-commit (&optional attach-dir)
|
||||
"Commit changes to git if `org-attach-id-dir' is properly initialized.
|
||||
This checks for the existence of a \".git\" directory in that directory."
|
||||
This checks for the existence of a \".git\" directory in that directory.
|
||||
|
||||
Takes one optional argument ATTACH-DIR for the sake of being
|
||||
compatible with hook `org-attach-after-change-hook'."
|
||||
(let* ((dir (expand-file-name org-attach-id-dir))
|
||||
(git-dir (vc-git-root dir))
|
||||
(use-annex (org-attach-git-use-annex))
|
||||
|
|
|
@ -33,12 +33,12 @@
|
|||
,@body))))
|
||||
|
||||
(ert-deftest test-org-attach-git/use-annex ()
|
||||
(test-org-attach-annex/with-annex
|
||||
(test-org-attach-git/with-annex
|
||||
(let ((org-attach-git-annex-cutoff 1))
|
||||
(should (org-attach-use-annex)))
|
||||
(should (org-attach-git-use-annex)))
|
||||
|
||||
(let ((org-attach-git-annex-cutoff nil))
|
||||
(should-not (org-attach-use-annex))))
|
||||
(should-not (org-attach-git-use-annex))))
|
||||
|
||||
;; test with non annex directory
|
||||
(let ((tmpdir (make-temp-file "org-annex-test" t "/")))
|
||||
|
@ -46,11 +46,11 @@
|
|||
(let ((default-directory tmpdir)
|
||||
(org-attach-id-dir tmpdir))
|
||||
(shell-command "git init")
|
||||
(should-not (org-attach-use-annex)))
|
||||
(should-not (org-attach-git-use-annex)))
|
||||
(delete-directory tmpdir 'recursive))))
|
||||
|
||||
(ert-deftest test-org-attach-git/get-maybe ()
|
||||
(test-org-attach-annex/with-annex
|
||||
(test-org-attach-git/with-annex
|
||||
(let ((path (expand-file-name "test-file"))
|
||||
(annex-dup (make-temp-file "org-annex-test" t "/")))
|
||||
(with-temp-buffer
|
||||
|
@ -71,21 +71,21 @@
|
|||
(shell-command "git annex drop --force test-file")
|
||||
;; test getting the file from the dup when we should ALWAYS get
|
||||
(should (not (file-exists-p (file-symlink-p (expand-file-name "test-file")))))
|
||||
(let ((org-attach-annex-auto-get t))
|
||||
(org-attach-annex-get-maybe (expand-file-name "test-file"))
|
||||
(let ((org-attach-git-annex-auto-get t))
|
||||
(org-attach-git-annex-get-maybe (expand-file-name "test-file"))
|
||||
;; check that the file has the right contents
|
||||
(with-temp-buffer
|
||||
(insert-file-contents path)
|
||||
(should (string-equal "hello world\n" (buffer-string)))))
|
||||
;; test getting the file from the dup when we should NEVER get
|
||||
(shell-command "git annex drop --force test-file")
|
||||
(let ((org-attach-annex-auto-get nil))
|
||||
(should-error (org-attach-annex-get-maybe (expand-file-name "test-file"))))
|
||||
(let ((org-attach-annex-auto-get 'ask)
|
||||
(let ((org-attach-git-annex-auto-get nil))
|
||||
(should-error (org-attach-git-annex-get-maybe (expand-file-name "test-file"))))
|
||||
(let ((org-attach-git-annex-auto-get 'ask)
|
||||
(called nil))
|
||||
(cl-letf (((symbol-function 'y-or-n-p)
|
||||
(lambda (_) (setq called 'was-called) t)))
|
||||
(org-attach-annex-get-maybe (expand-file-name "test-file"))
|
||||
(org-attach-git-annex-get-maybe (expand-file-name "test-file"))
|
||||
;; check that the file has the right contents
|
||||
(with-temp-buffer
|
||||
(insert-file-contents path)
|
||||
|
|
|
@ -108,12 +108,14 @@
|
|||
(ert-deftest test-org-attach/dired-attach-to-next-best-subtree/1 ()
|
||||
"Attach file at point in dired to subtree."
|
||||
(should
|
||||
(let ((a-filename (make-temp-file "a"))) ; file is an attach candidate.
|
||||
(let ((a-filename (make-temp-file "a")) ; file is an attach candidate.
|
||||
(org-attach-id-dir "data/"))
|
||||
(unwind-protect
|
||||
(org-test-with-temp-text-in-file
|
||||
"* foo :foo:"
|
||||
(split-window)
|
||||
(dired temporary-file-directory)
|
||||
(let ((org-buffer (current-buffer))
|
||||
(dired-buffer (dired temporary-file-directory)))
|
||||
(cl-assert (eq 'dired-mode major-mode))
|
||||
(revert-buffer)
|
||||
(dired-goto-file a-filename)
|
||||
|
@ -121,7 +123,8 @@
|
|||
(call-interactively #'org-attach-dired-to-subtree)
|
||||
; check
|
||||
(delete-window)
|
||||
(cl-assert (eq 'org-mode major-mode))
|
||||
(switch-to-buffer org-buffer)
|
||||
(cl-assert (eq 'org-mode major-mode)))
|
||||
(beginning-of-buffer)
|
||||
(search-forward "* foo")
|
||||
; expectation. tag ATTACH has been appended.
|
||||
|
@ -136,12 +139,14 @@
|
|||
"Attach 2 marked files."
|
||||
(should
|
||||
(let ((a-filename (make-temp-file "a"))
|
||||
(b-filename (make-temp-file "b"))) ; attach candidates.
|
||||
(b-filename (make-temp-file "b")) ; attach candidates.
|
||||
(org-attach-id-dir "data/"))
|
||||
(unwind-protect
|
||||
(org-test-with-temp-text-in-file
|
||||
"* foo"
|
||||
(split-window)
|
||||
(dired temporary-file-directory)
|
||||
(let ((org-buffer (current-buffer))
|
||||
(dired-buffer (dired temporary-file-directory)))
|
||||
(cl-assert (eq 'dired-mode major-mode))
|
||||
(revert-buffer)
|
||||
(dired-goto-file a-filename)
|
||||
|
@ -152,6 +157,7 @@
|
|||
(call-interactively #'org-attach-dired-to-subtree)
|
||||
; check
|
||||
(delete-window)
|
||||
(switch-to-buffer org-buffer))
|
||||
(cl-assert (eq 'org-mode major-mode))
|
||||
(beginning-of-buffer)
|
||||
(search-forward "* foo")
|
||||
|
|
Loading…
Reference in New Issue