magit/magit — comment on commit d4a3dff143efbecd62f86b2bf2b307a74a6473cd
File:  line 0
By DarwinAwardWinner:

Hmm. I have `delete-trailing-whitespace` in my before-save-hook. It's probably easiest for me to do this:

(defadvice delete-trailing-whitespace (around disable-when-read-only activate)
"Do nothing if buffer is read only"
(unless buffer-read-only
ad-do-it))

However, in general having buffer-modifying stuff in `before-save-hook` could be a problem with this mode. The following should disable `before-save-hook` in rebase-mode, if that's a better solution:

(defadvice server-edit (around no-before-save-hook-in-rebase activate)
"Disable `before-save-hook' in rebase-mode."
(let ((before-save-hook
(when (not (eq major-mode
'rebase-mode))
before-save-hook)))
ad-do-it))

Maybe we could call every element of `before-save-hook` wrapped in `ignore-errors` with `buffer-read-only` set to t, so that all the "good" ones will succeed but hooks that modify the buffer would be stopped. How does that sound?