From: Sean Whitton <spwhitton@spwhitton.name>
To: 60126@debbugs.gnu.org
Cc: juri@linkov.net, dgutov@yandex.ru
Subject: bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes
Date: Fri, 16 Dec 2022 18:32:54 +0000 [thread overview]
Message-ID: <Y5y51lQ2Nnlc6Mst@athena.silentflame.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 202 bytes --]
X-debbugs-cc: juri@linkov.net, dgutov@yandex.ru
I seem often to end up with a nonempty index when trying to commit patches
using C-x v v from diff-mode, so I came up with this patch.
--
Sean Whitton
[-- Attachment #2: 0001-vc-git-checkin-Offer-to-unstage-conflicting-changes.patch --]
[-- Type: text/x-diff, Size: 3372 bytes --]
From b30ed86e2d2277c94a6655e9ebdeb8253805899d Mon Sep 17 00:00:00 2001
From: Sean Whitton <spwhitton@spwhitton.name>
Date: Fri, 16 Dec 2022 11:28:20 -0700
Subject: [PATCH] vc-git-checkin: Offer to unstage conflicting changes
* lisp/vc/vc-git.el (vc-git-checkin): When committing a patch, if
conflicting changes are already staged, offer to clear them, instead
of just immediately failing with "Index not empty".
---
lisp/vc/vc-git.el | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 2876a983fb0..dcb51bb933f 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1030,23 +1030,33 @@ vc-git-checkin
(with-temp-buffer
(vc-git-command (current-buffer) t nil "diff" "--cached")
(goto-char (point-min))
- (let ((pos (point)) file-diff file-beg)
+ (let ((pos (point)) file-name file-diff file-beg)
(while (not (eobp))
+ (when (looking-at "^diff --git a/.+ b/\\(.+\\)")
+ (setq file-name (match-string 1)))
(forward-line 1) ; skip current "diff --git" line
(search-forward "diff --git" nil 'move)
(move-beginning-of-line 1)
(setq file-diff (buffer-substring pos (point)))
- (if (and (setq file-beg (string-search
- file-diff vc-git-patch-string))
- ;; Check that file diff ends with an empty string
- ;; or the beginning of the next file diff.
- (string-match-p "\\`\\'\\|\\`diff --git"
- (substring
- vc-git-patch-string
- (+ file-beg (length file-diff)))))
- (setq vc-git-patch-string
- (string-replace file-diff "" vc-git-patch-string))
- (user-error "Index not empty"))
+ (cond ((and (setq file-beg (string-search
+ file-diff vc-git-patch-string))
+ ;; Check that file diff ends with an empty string
+ ;; or the beginning of the next file diff.
+ (string-match-p "\\`\\'\\|\\`diff --git"
+ (substring
+ vc-git-patch-string
+ (+ file-beg (length file-diff)))))
+ (setq vc-git-patch-string
+ (string-replace file-diff "" vc-git-patch-string)))
+ ((and file-name
+ ;; Check the regexp extracted an actual file
+ ;; from the 'diff --git' line.
+ (file-exists-p (expand-file-name file-name root))
+ (yes-or-no-p
+ (format "Unstage already-staged changes to %s?"
+ file-name)))
+ (vc-git-command nil 0 file-name "reset" "-q" "--"))
+ (t (user-error "Index not empty")))
(setq pos (point))))))
(let ((patch-file (make-nearby-temp-file "git-patch")))
(with-temp-file patch-file
--
2.30.2
next reply other threads:[~2022-12-16 18:32 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-16 18:32 Sean Whitton [this message]
2022-12-17 17:06 ` bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes Juri Linkov
2022-12-18 0:20 ` Sean Whitton
2022-12-18 1:08 ` Dmitry Gutov
2022-12-19 22:30 ` Sean Whitton
2022-12-20 0:53 ` Dmitry Gutov
2022-12-20 6:43 ` Sean Whitton
2022-12-20 13:47 ` Dmitry Gutov
2022-12-20 16:47 ` Sean Whitton
2022-12-20 15:13 ` Dmitry Gutov
2022-12-20 17:04 ` Sean Whitton
2022-12-20 23:10 ` Sean Whitton
2022-12-20 23:41 ` Sean Whitton
2022-12-20 23:45 ` Dmitry Gutov
2022-12-23 0:12 ` Sean Whitton
2022-12-23 3:59 ` Sean Whitton
2022-12-23 8:16 ` Eli Zaretskii
2022-12-24 2:03 ` Sean Whitton
2022-12-23 23:18 ` Dmitry Gutov
2022-12-24 2:02 ` Sean Whitton
2022-12-24 14:50 ` Dmitry Gutov
2022-12-24 18:22 ` Sean Whitton
2022-12-24 19:26 ` Dmitry Gutov
2022-12-24 20:10 ` Sean Whitton
2022-12-23 22:55 ` Dmitry Gutov
2022-12-20 17:13 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y5y51lQ2Nnlc6Mst@athena.silentflame.com \
--to=spwhitton@spwhitton.name \
--cc=60126@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.