Browse Source

Restore working directory after computing org-version

Sebastian Rose writes

>   1. Open an *.org file you can export to PDF. Ensure the file is not
>      located where your Org-mode sources are (org-*.el files). Choose a
>      file, that includes some images or a SETUPFILE using relative
>      paths.
>   2. M-x default-directory RET
>      to see the value of that variable in the current buffer.
>   3. C-c C-e p
>      to export to PDF and verify it works.
>   4. C-c C-x !
>      to `org-reload'
>   5. Now repeat steps 2 and 3. Note, that the export fails.

Sebastian also submitted the basic patch to fix this
Carsten Dominik 15 years ago
parent
commit
8d7d158013
1 changed files with 17 additions and 16 deletions
  1. 17 16
      lisp/org.el

+ 17 - 16
lisp/org.el

@@ -102,28 +102,29 @@
   "Show the org-mode version in the echo area.
 With prefix arg HERE, insert it at point."
   (interactive "P")
-  (let* ((version org-version)
+  (let* ((origin default-directory)
+	 (version org-version)
 	 (git-version)
 	 (dir (concat (file-name-directory (locate-library "org")) "../" )))
-    (if (and (file-exists-p (expand-file-name ".git" dir))
-	     (executable-find "git"))
-	(let ((pwd (substring (pwd) 10)))
-	  (cd dir)
-	  (if (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
+    (when (and (file-exists-p (expand-file-name ".git" dir))
+	       (executable-find "git"))
+      (unwind-protect
+	  (progn
+	    (cd dir)
+	    (when (eql 0 (shell-command "git describe --abbrev=4 HEAD"))
 	      (with-current-buffer "*Shell Command Output*"
 		(goto-char (point-min))
-		(re-search-forward "[^\n]+")
-		(setq git-version (match-string 0))
-		(subst-char-in-string ?- ?. git-version t)
-		(shell-command "git diff-index --name-only HEAD --")
-		(unless (eql 1 (point-max))
-		  (setq git-version (concat git-version ".dirty")))
-		(setq version (concat version " (" git-version ")")))
-	    (cd pwd))))
+		(setq git-version (buffer-substring (point) (point-at-eol))))
+	      (subst-char-in-string ?- ?. git-version t)
+	      (when (string-match "\\S-"
+				  (shell-command-to-string
+				   "git diff-index --name-only HEAD --"))
+		(setq git-version (concat git-version ".dirty")))
+	      (setq version (concat version " (" git-version ")"))))
+	(cd origin)))
     (setq version (format "Org-mode version %s" version))
     (if here (insert version))
-    (message version)
-    version))
+    (message version)))
 
 ;;; Compatibility constants