[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#52349: 29.0.50; vc-git and diff-mode: stage hunks
From: |
Juri Linkov |
Subject: |
bug#52349: 29.0.50; vc-git and diff-mode: stage hunks |
Date: |
Sun, 11 Sep 2022 18:05:20 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu) |
>> 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?
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))
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Juri Linkov, 2022/09/08
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Sean Whitton, 2022/09/08
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Dmitry Gutov, 2022/09/09
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks,
Juri Linkov <=
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Dmitry Gutov, 2022/09/11
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Juri Linkov, 2022/09/12
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Dmitry Gutov, 2022/09/18
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Juri Linkov, 2022/09/19
- bug#52349: 29.0.50; vc-git and diff-mode: stage hunks, Dmitry Gutov, 2022/09/19