unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: 52349@debbugs.gnu.org, Sean Whitton <spwhitton@spwhitton.name>
Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks
Date: Sun, 11 Sep 2022 18:05:20 +0300	[thread overview]
Message-ID: <868rmqypjz.fsf@mail.linkov.net> (raw)
In-Reply-To: <eae9cd95-cb31-7cb7-b6a2-039e9b820714@yandex.ru> (Dmitry Gutov's message of "Sat, 10 Sep 2022 04:36:35 +0300")

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

>> Would it be too disruptive to make "registering" a new file with Git a
>> no-op, and then require the user to commit it by going to VC Dir and
>> marking it?  That's the only alternative I can think of, given that it's
>> common to have lots of untracked, unignored files around you don't
>> intend ever to commit.
>
> I suppose we could use a more complex check in Git's case: if the diff is
> non-empty, check that it doesn't intersect with the diff we want to apply,
> or where it does, the contents are exactly the same. It's more complex than
> the existing one-liner, though.

Maybe like this?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vc-git-checkin-diff-cached.patch --]
[-- Type: text/x-diff, Size: 1180 bytes --]

diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 2941cc75be..792981b142 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1018,7 +1018,20 @@ vc-git-checkin
                 (make-nearby-temp-file "git-msg")))))
     (when vc-git-patch-string
       (unless (zerop (vc-git-command nil t nil "diff" "--cached" "--quiet"))
-        (user-error "Index not empty"))
+        (with-temp-buffer
+          (vc-git-command (current-buffer) t nil "diff" "--cached")
+          (goto-char (point-min))
+          (let ((pos (point)) file-diff)
+            (forward-line 1)
+            (while (not (eobp))
+              (search-forward "diff --git" nil 'move)
+              (move-beginning-of-line 1)
+              (setq file-diff (buffer-substring pos (point)))
+              (if (string-search file-diff vc-git-patch-string)
+                  (setq vc-git-patch-string
+                        (string-replace file-diff "" vc-git-patch-string))
+                (user-error "Index not empty"))
+              (setq pos (point))))))
       (let ((patch-file (make-temp-file "git-patch")))
         (with-temp-file patch-file
           (insert vc-git-patch-string))

  reply	other threads:[~2022-09-11 15:05 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-07  8:59 bug#52349: 29.0.50; vc-git and diff-mode: stage hunks Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-07 17:03 ` Juri Linkov
2021-12-07 17:08   ` Manuel Uberti via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-12-07 19:04     ` Juri Linkov
2021-12-07 17:10 ` Dmitry Gutov
2021-12-07 19:06   ` Juri Linkov
2021-12-08  2:29     ` Dmitry Gutov
2021-12-08 18:57       ` Juri Linkov
2021-12-09 23:17         ` Dmitry Gutov
2022-02-08 19:57           ` Juri Linkov
2022-02-12  1:43             ` Dmitry Gutov
2022-02-12 19:42               ` Juri Linkov
2022-02-13  1:32                 ` Dmitry Gutov
2022-02-13 19:48                   ` Juri Linkov
2022-02-13 22:51                     ` Dmitry Gutov
2022-02-13 19:56                   ` Juri Linkov
2022-02-13 22:41                     ` Dmitry Gutov
2022-08-21 16:07                       ` Juri Linkov
2022-02-13 22:37                   ` Dmitry Gutov
2022-08-21 18:53                     ` Juri Linkov
2022-08-24  2:06                       ` Dmitry Gutov
2022-08-24 18:20                         ` Juri Linkov
2022-08-24 20:20                           ` Dmitry Gutov
2022-08-27 20:07                             ` Juri Linkov
2022-08-28  0:40                               ` Dmitry Gutov
2022-08-28 19:45                                 ` Juri Linkov
2022-08-28 23:34                                   ` Dmitry Gutov
2022-09-08 19:29                             ` Juri Linkov
2022-09-08 22:48                               ` Sean Whitton
2022-09-10  1:36                                 ` Dmitry Gutov
2022-09-11 15:05                                   ` Juri Linkov [this message]
2022-09-11 21:57                                     ` Dmitry Gutov
2022-09-12 18:19                                       ` Juri Linkov
2022-09-19  2:09                                         ` Dmitry Gutov
2022-09-19  6:50                                           ` Juri Linkov
2022-09-19 12:57                                             ` Dmitry Gutov
2022-10-02 18:51                                               ` Juri Linkov
2022-11-04  1:32                                                 ` Dmitry Gutov
2022-08-26 17:11                       ` Filipp Gunbin
2022-08-27 19:56                         ` Juri Linkov
2021-12-07 20:07 ` Lars Ingebrigtsen

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=868rmqypjz.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=52349@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=spwhitton@spwhitton.name \
    /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 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).