From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#52349: 29.0.50; vc-git and diff-mode: stage hunks Date: Sun, 11 Sep 2022 18:05:20 +0300 Organization: LINKOV.NET Message-ID: <868rmqypjz.fsf@mail.linkov.net> References: <268cee0d-465d-b862-d1d6-f5da4d69e737@inventati.org> <9106387a-98cf-396f-bf45-ccb04581787b@yandex.ru> <864k7kfd56.fsf@mail.linkov.net> <86fsr3uen2.fsf@mail.linkov.net> <95d2d999-49ad-13c4-9f25-0935650a1e42@yandex.ru> <8635ktjfll.fsf@mail.linkov.net> <36b963e4-5af7-dd9e-af92-4404541b9f4d@yandex.ru> <86v8xjx45h.fsf@mail.linkov.net> <861qt9h1hh.fsf@mail.linkov.net> <864jy1mrk8.fsf@mail.linkov.net> <86fsh1ll5y.fsf@mail.linkov.net> <87edwlo52t.fsf@melete.silentflame.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5924"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) Cc: 52349@debbugs.gnu.org, Sean Whitton To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 11 17:12:14 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oXOd3-0001JZ-Kk for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 17:12:13 +0200 Original-Received: from localhost ([::1]:33702 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oXOd2-00036Z-L6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Sep 2022 11:12:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oXOcs-00032o-Hv for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 11:12:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54483) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oXOcs-0002WJ-4z for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 11:12:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oXOcs-0002tx-0O for bug-gnu-emacs@gnu.org; Sun, 11 Sep 2022 11:12:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Sep 2022 15:12:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52349 X-GNU-PR-Package: emacs Original-Received: via spool by 52349-submit@debbugs.gnu.org id=B52349.166290910911113 (code B ref 52349); Sun, 11 Sep 2022 15:12:01 +0000 Original-Received: (at 52349) by debbugs.gnu.org; 11 Sep 2022 15:11:49 +0000 Original-Received: from localhost ([127.0.0.1]:43178 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXOcf-0002tB-5P for submit@debbugs.gnu.org; Sun, 11 Sep 2022 11:11:49 -0400 Original-Received: from relay4-d.mail.gandi.net ([217.70.183.196]:49299) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oXOcd-0002sr-3F for 52349@debbugs.gnu.org; Sun, 11 Sep 2022 11:11:47 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by mail.gandi.net (Postfix) with ESMTPSA id 315BDE0005; Sun, 11 Sep 2022 15:11:36 +0000 (UTC) In-Reply-To: (Dmitry Gutov's message of "Sat, 10 Sep 2022 04:36:35 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242176 Archived-At: --=-=-= Content-Type: text/plain >> 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? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-git-checkin-diff-cached.patch 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)) --=-=-=--