From 7c84984d356f72f1a39d15def6b98fa6ad5b0f3c Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 21 Dec 2022 10:30:03 -0700 Subject: mailscripts.el: don't offer to detach a HEAD that's already detached Signed-off-by: Sean Whitton --- debian/changelog | 1 + mailscripts.el | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6d237a8..d0f983b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,6 +10,7 @@ mailscripts (28-1) UNRELEASED; urgency=medium - if mailscripts-extract-message-patches identifies no attachments, it now offers to pipe the whole message to 'git am' + - don't offer to detach a HEAD that's already detached - rewrite short description and add a brief commentary - load the notmuch library only when code that requires it is called - move the mailscripts customisation group into the mail group diff --git a/mailscripts.el b/mailscripts.el index 610e337..a7a8240 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -395,9 +395,13 @@ See also the interactive wrapper command `mailscripts-prepare-patch'." (defun mailscripts--check-out-branch (branch) (if (string= branch "") - (when (or (eq mailscripts-detach-head-from-existing-branch t) - (and (eq mailscripts-detach-head-from-existing-branch 'ask) - (yes-or-no-p "Detach HEAD before applying patches?"))) + (when (and + ;; Don't proceed if HEAD is already detached. + (zerop (call-process "git" nil nil nil + "symbolic-ref" "--quiet" "HEAD")) + (or (eq mailscripts-detach-head-from-existing-branch t) + (and (eq mailscripts-detach-head-from-existing-branch 'ask) + (yes-or-no-p "Detach HEAD before applying patches?")))) (call-process-shell-command "git checkout --detach")) (call-process-shell-command (format "git checkout -b %s" -- cgit v1.2.3