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 --- mailscripts.el | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'mailscripts.el') 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