From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sean Whitton Newsgroups: gmane.emacs.bugs Subject: bug#60126: 30.0.50; vc-git-checkin: Offer to unstage conflicting changes Date: Fri, 16 Dec 2022 18:32:54 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="PTDfVvaC6/GuvJJJ" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31894"; mail-complaints-to="usenet@ciao.gmane.io" Cc: juri@linkov.net, dgutov@yandex.ru To: 60126@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Dec 16 19:34:32 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 1p6FXS-000800-Lo for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 16 Dec 2022 19:34:32 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6FX2-0003wq-QI; Fri, 16 Dec 2022 13:34:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6FX1-0003ui-Cf for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:34:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p6FX1-0007HC-0t for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:34:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p6FWz-0005Cg-QW; Fri, 16 Dec 2022 13:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Sean Whitton Original-Sender: "Debbugs-submit" Resent-CC: juri@linkov.net, dgutov@yandex.ru, bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Dec 2022 18:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60126 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: juri@linkov.net, dgutov@yandex.ru Original-Received: via spool by submit@debbugs.gnu.org id=B.167121558619975 (code B ref -1); Fri, 16 Dec 2022 18:34:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 16 Dec 2022 18:33:06 +0000 Original-Received: from localhost ([127.0.0.1]:50880 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6FW6-0005C7-8x for submit@debbugs.gnu.org; Fri, 16 Dec 2022 13:33:06 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:52190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p6FW2-0005C1-28 for submit@debbugs.gnu.org; Fri, 16 Dec 2022 13:33:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6FW1-0003bz-JH for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:33:01 -0500 Original-Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6FVz-000792-HF for bug-gnu-emacs@gnu.org; Fri, 16 Dec 2022 13:33:01 -0500 Original-Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id D3FD95C003D for ; Fri, 16 Dec 2022 13:32:56 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 16 Dec 2022 13:32:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=spwhitton.name; h=cc:content-type:date:date:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t= 1671215576; x=1671301976; bh=HvQGyctllnKUunpdmwisukdhBO+N4RZgWpw ZICMip3I=; b=ny8D2mj+tJYb0C23LkOY+R9+nLrUs9toXASffJZaRgmc7hDh9KQ 5nO+wIUOm8VvtAlWLRE96eZNzcrDmKyJeW3VtGkTMgKwqAcVmE0JRFVKiPODcbUj 7YXkkEOwXCy5yT6qZOzNAs0HqjVRGbbrjKiBk2FDOtP8cykieiMfjv43PbeYC6ie rJHEjVCaB5dqSWrPSij450EMXna3LY1OURYpbVG53Ox6ZG/fByzdcSQdhdhCdnB2 eB7yaHc0IWgaKQgb8t+CLTzDa+bvWH2EW0sQKHtNKAHGX4lQrvzQiivr7WPRjSA1 Ed2Ow1MWqbk3U8R51Y43CwsHyo2+waQx0Xg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1671215576; x= 1671301976; bh=HvQGyctllnKUunpdmwisukdhBO+N4RZgWpwZICMip3I=; b=Q v7/qKDOL5t4RDWlZfYMULWDUqukmJIkCxBLgURMPICaq8xi/EPvSRfTJ+h7JnVrI qg7OSI6tWDbx43Jyll26Ijlju+Qtwm8BJNe69KYTocR7gTH4xMdbSA0igYb0P3Bt KhpOaxnHEZYkySCUTh8J+e1bCJceTomB+RR6UV3qW8zk8mVQnTl8leCrlO9O/iqu ceolC9Q8aNhQDLAkBQm2OqYtmXS0VF5laKgMqdjEtyUK+mSNX9S1yZn2EQXh7J9R snJpXGRHNrJf/ZgUkmcWbh+HSfxgApJ4k9Rsabe9A+Sfikbl0NN6nsGjRONi1b4K 6Uh/TZVKUCja+WnnImgiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeejgdduudduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugesmhdttdertd dtvdenucfhrhhomhepufgvrghnucghhhhithhtohhnuceoshhpfihhihhtthhonhesshhp fihhihhtthhonhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpeelhfevhffhvefgteeffe etueeuieekvdfftddtveevkeelffejffevffdugeejgfenucevlhhushhtvghrufhiiigv pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehsphifhhhithhtohhnsehsphifhhhith htohhnrdhnrghmvg X-ME-Proxy: Feedback-ID: i23c04076:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 16 Dec 2022 13:32:56 -0500 (EST) Original-Received: by athena.silentflame.com (Postfix, from userid 1000) id 6A63E1B6346; Fri, 16 Dec 2022 18:32:54 +0000 (UTC) Content-Disposition: inline Received-SPF: pass client-ip=66.111.4.28; envelope-from=spwhitton@spwhitton.name; helo=out4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251231 Archived-At: --PTDfVvaC6/GuvJJJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --PTDfVvaC6/GuvJJJ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-vc-git-checkin-Offer-to-unstage-conflicting-changes.patch" >From b30ed86e2d2277c94a6655e9ebdeb8253805899d Mon Sep 17 00:00:00 2001 From: Sean Whitton 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 --PTDfVvaC6/GuvJJJ--