DOOM Emacs -> ambiguous argument 'HEAD': unknown revision or path not in the working tree

2024-05-10

It is funny that DOOM Emacs breaks every time in a few days I install it. It always happens with the upgrade, it suddenly starts throwing an error like this:

  > Updating all packages (this may take a while)...
    x The package manager threw an error-date...
    x Last 16 lines of straight's error log:
      [Return code: 0]
      $ cd /Users/as/.config/emacs/.local/straight/repos/vundo/
      $ git rev-parse HEAD
      10d011fb05a9db0cc2f641e5b5bebe4b5fb81b6f
      [Return code: 0]
      $ cd /Users/as/.config/emacs/.local/straight/repos/emacs-undo-fu-session/
      $ git rev-parse HEAD
      2b355c9d39b2688f859a762f2289f23fd16fadc4
      [Return code: 0]
      $ cd /Users/as/.config/emacs/.local/straight/repos/emacs-undo-fu/
      $ git rev-parse HEAD
      HEAD
      fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
      Use '--' to separate paths from revisions, like this:
      'git <command> [<revision>...] -- [<file>...]'
      [Return code: 128]

I tried doom doctor, doom sync, whatever, nothing worked. First few times I just re-installed DOOM Emacs, but this time I decided to fix it. The fix that worked for me is to find the last repository name before the error appears: fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree. - in this case it is /Users/as/.config/emacs/.local/straight/repos/emacs-undo-fu/ - and just remove the folder:

rm -rf ~/.config/emacs/.local/straight/repos/emacs-undo-fu

You might need to repeat this process a few times, for other repositories. After that, just run doom sync (or doom upgrade or where it broke) and it should work.

Conclusion#

I don't know why this happens, but it is a quick fix. I hope it helps you too.