emacscollective / borg

Assimilate Emacs packages as Git submodules
https://emacsmirror.net/manual/borg
GNU General Public License v3.0
255 stars 28 forks source link

Fallback for borg-top-level-directory #110

Closed chasecaleb closed 3 years ago

chasecaleb commented 3 years ago

Commit bbea37f99e3bf6c0028d2fefdefce52019af84d8 introduced borg-top-level-directory, which uses git rev-parse --show-toplevel. Unfortunately because I use a CI/CD process to build my Emacs init into an OS package instead of cloning my init source repo, I do not have .git dirs so the git rev-parse command errors. Could you add a fallback for this, please? It looks like you already have fallback logic in a few places such as for borg-drones-dir, so adding something similar to borg-top-level-directory should work: https://github.com/emacscollective/borg/blob/6ea061f30065493e206132ff3f7a2d8febb859d0/borg.el#L78-L94

Personally I have no plans to use a monorepo layout so I would be fine if the fallback assumes borg-user-emacs-directory is at the top level of repo like the past behavior. Or maybe you could change borg-user-emacs-directory from defconst to defvar so that I could define it in my own init before loading borg. Your elisp skills are far superior to mine though, so I'm probably pointing out the obvious.

Here's the error with /usr/bin/emacs --debug-init:

Debugger entered--Lisp error: (error "git exited with status 128")
  signal(error ("git exited with status 128"))
  error("%s exited with status %s" "git" 128)
  process-lines("git" "rev-parse" "--show-toplevel")
  byte-code("\10\31\302\303\304\305\306#@!)\207" [borg-user-emacs-directory default-directory file-name-as-directory process-lines "git" "rev-parse" "--show-toplevel"] 5)
  (defconst borg-top-level-directory (byte-code "\10\31\302\303\304\305\306#@!)\207" [borg-user-emacs-directory default-directory file-name-as-directory process-lines "git" "rev-parse" "--show-toplevel"] 5) ("/home/caleb/.emacs.d/lib/borg/borg.elc" . 1813))
  #<subr require>(borg)
  apply(#<subr require> borg)
  require(borg)
  byte-code("\306 \210\307\310\306\"\210\307\311\312\"\210\10\206\22\0\11\22\313\n!\23\314\211\24\25\314\211\26\36\26\37\315\26 \316\317!\210\320\317!\210\321\317!\210\322\317..." [load-file-name buffer-file-name user-init-file user-emacs-directory inhibit-startup-buffer-menu inhibit-startup-screen cc/gc-increase add-hook minibuffer-setup-hook minibuffer-exit-hook cc/gc-restore file-name-directory t "" scroll-bar-mode 0 horizontal-scroll-bar-mode tool-bar-mode menu-bar-mode add-to-list load-path expand-file-name "lib/borg" require borg (("git@code.orgmode.org:" . "https://code.orgmode.org/")) borg-initialize bind-key nil diminish inhibit-compacting-font-caches initial-buffer-choice initial-scratch-message Info-default-directory-list Info-directory-list borg-rewrite-urls-alist] 6)
  #<subr load>("/home/caleb/.emacs.d/init" noerror nomessage nil nil)
  apply(#<subr load> ("/home/caleb/.emacs.d/init" noerror nomessage))
  load("/home/caleb/.emacs.d/init" noerror nomessage)
  startup--load-user-init-file(#f(compiled-function () #<bytecode 0x15721527af9d>) #f(compiled-function () #<bytecode 0x15721527afb5>) t)
  command-line()
  normal-top-level()

To make it more obvious what's going on:

caleb@arch-as-code-desktop> ls -l ~/.emacs.d
lrwxrwxrwx 1 caleb caleb 10 Dec 11  2020 /home/caleb/.emacs.d -> /etc/emacs
caleb@arch-as-code-desktop> cd /etc/emacs 
caleb@arch-as-code-desktop> git rev-parse --show-toplevel
fatal: not a git repository (or any of the parent directories): .git
[128] caleb@arch-as-code-desktop> ls -la
total 480
drwxr-xr-x 1 root root    228 Aug 11 19:02 .
drwxr-xr-x 1 root root   2944 Aug 11 19:02 ..
-rw-r--r-- 1 root root    296 Aug 11 19:02 authinfo.gpg
-rwxr-xr-x 1 root root   1318 Aug 11 19:02 do-borg.el
-rw-r--r-- 1 root root    977 Aug 11 19:02 early-init.el
-rw-r--r-- 1 root root   9710 Aug 11 19:02 .gitmodules
-rw-r--r-- 1 root root 106591 Aug 11 19:02 init.el
-rw-r--r-- 1 root root 336883 Aug 11 19:02 init.elc
-rw-r--r-- 1 root root    477 Aug 11 19:02 init-helm-tramp.el
drwxr-xr-x 1 root root   1628 Aug  5 17:03 lib
-rw-r--r-- 1 root root   1068 Aug 11 19:02 LICENSE
-rw-r--r-- 1 root root     85 Aug 11 19:02 Makefile
-rw-r--r-- 1 root root    839 Aug 11 19:02 README.md
drwxr-xr-x 1 root root     30 Dec 11  2020 snippets
caleb@arch-as-code-desktop> find . -type d -name '.git' | wc -l
0

I'm open to making a PR if that would help, just point me in the right direction towards what solution you would prefer.

For context, you might remember me from this magit issue with the same edge case - although with magit it was just a warning message, whereas in this case borg crashes so it's a bigger problem.

Thanks!

chasecaleb commented 3 years ago

Verified that this works, thank you! :100:

tarsius commented 3 years ago

You're welcome!