diff options
| author | Sean Whitton | 2022-12-16 11:28:20 -0700 |
|---|---|---|
| committer | Sean Whitton | 2022-12-20 16:09:12 -0700 |
| commit | 962bdfcdfe7e27687021c7dbaf0bb292afe9483c (patch) | |
| tree | 7a3e3ddc3954db6f8cbe155accf77ad44a091f33 | |
| parent | 9fafeb2a66fe1cba8f3ad7662196e36ca0b1eca7 (diff) | |
| download | emacs-962bdfcdfe7e27687021c7dbaf0bb292afe9483c.tar.gz emacs-962bdfcdfe7e27687021c7dbaf0bb292afe9483c.zip | |
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" (bug#60126).
| -rw-r--r-- | lisp/vc/vc-git.el | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el index 9f27f759d35..8f995021dcc 100644 --- a/lisp/vc/vc-git.el +++ b/lisp/vc/vc-git.el | |||
| @@ -1030,23 +1030,31 @@ It is based on `log-edit-mode', and has Git-specific extensions." | |||
| 1030 | (with-temp-buffer | 1030 | (with-temp-buffer |
| 1031 | (vc-git-command (current-buffer) t nil "diff" "--cached") | 1031 | (vc-git-command (current-buffer) t nil "diff" "--cached") |
| 1032 | (goto-char (point-min)) | 1032 | (goto-char (point-min)) |
| 1033 | (let ((pos (point)) file-diff file-beg) | 1033 | (let ((pos (point)) file-name file-diff file-beg) |
| 1034 | (while (not (eobp)) | 1034 | (while (not (eobp)) |
| 1035 | (when (and (looking-at "^diff --git a/\\(.+\\) b/\\(.+\\)") | ||
| 1036 | (string= (match-string 1) (match-string 2))) | ||
| 1037 | (setq file-name (match-string 1))) | ||
| 1035 | (forward-line 1) ; skip current "diff --git" line | 1038 | (forward-line 1) ; skip current "diff --git" line |
| 1036 | (search-forward "diff --git" nil 'move) | 1039 | (search-forward "diff --git" nil 'move) |
| 1037 | (move-beginning-of-line 1) | 1040 | (move-beginning-of-line 1) |
| 1038 | (setq file-diff (buffer-substring pos (point))) | 1041 | (setq file-diff (buffer-substring pos (point))) |
| 1039 | (if (and (setq file-beg (string-search | 1042 | (cond ((and (setq file-beg (string-search |
| 1040 | file-diff vc-git-patch-string)) | 1043 | file-diff vc-git-patch-string)) |
| 1041 | ;; Check that file diff ends with an empty string | 1044 | ;; Check that file diff ends with an empty string |
| 1042 | ;; or the beginning of the next file diff. | 1045 | ;; or the beginning of the next file diff. |
| 1043 | (string-match-p "\\`\\'\\|\\`diff --git" | 1046 | (string-match-p "\\`\\'\\|\\`diff --git" |
| 1044 | (substring | 1047 | (substring |
| 1045 | vc-git-patch-string | 1048 | vc-git-patch-string |
| 1046 | (+ file-beg (length file-diff))))) | 1049 | (+ file-beg (length file-diff))))) |
| 1047 | (setq vc-git-patch-string | 1050 | (setq vc-git-patch-string |
| 1048 | (string-replace file-diff "" vc-git-patch-string)) | 1051 | (string-replace file-diff "" vc-git-patch-string))) |
| 1049 | (user-error "Index not empty")) | 1052 | ((and file-name |
| 1053 | (yes-or-no-p | ||
| 1054 | (format "Unstage already-staged changes to %s?" | ||
| 1055 | file-name))) | ||
| 1056 | (vc-git-command nil 0 file-name "reset" "-q" "--")) | ||
| 1057 | (t (user-error "Index not empty"))) | ||
| 1050 | (setq pos (point)))))) | 1058 | (setq pos (point)))))) |
| 1051 | (let ((patch-file (make-nearby-temp-file "git-patch"))) | 1059 | (let ((patch-file (make-nearby-temp-file "git-patch"))) |
| 1052 | (with-temp-file patch-file | 1060 | (with-temp-file patch-file |