unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes
@ 2022-12-16 18:32 Sean Whitton
  2022-12-17 17:06 ` Juri Linkov
  2022-12-18  1:08 ` Dmitry Gutov
  0 siblings, 2 replies; 26+ messages in thread
From: Sean Whitton @ 2022-12-16 18:32 UTC (permalink / raw)
  To: 60126; +Cc: juri, dgutov

[-- 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


^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2022-12-24 20:10 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-16 18:32 bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes Sean Whitton
2022-12-17 17:06 ` 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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).