aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2025-05-18 12:35:13 +0100
committerSean Whitton2025-05-18 12:35:13 +0100
commita4424fb8cd2d638ee348ee7fd08d0e5f397fad75 (patch)
tree214f76d7b22b1e35d7caea115fe7cc49aac3a284
parent913b4e1c97c0b8ec279cfcf62ed40b5b58393e44 (diff)
downloademacs-a4424fb8cd2d638ee348ee7fd08d0e5f397fad75.tar.gz
emacs-a4424fb8cd2d638ee348ee7fd08d0e5f397fad75.zip
Factor out vc-git--with-apply-temp-to-staging
* lisp/vc/vc-git.el (vc-git--with-apply-temp-to-staging): New macro. (vc-git-checkin): Use it.
-rw-r--r--lisp/vc/vc-git.el39
1 files changed, 22 insertions, 17 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 582de105c17..c75c61cb3f4 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -1111,6 +1111,19 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1111 ("Sign-Off" . ,(boolean-arg-fn "--signoff"))) 1111 ("Sign-Off" . ,(boolean-arg-fn "--signoff")))
1112 comment))) 1112 comment)))
1113 1113
1114(defmacro vc-git--with-apply-temp-to-staging (temp &rest body)
1115 (declare (indent 1) (debug (symbolp body)))
1116 `(let ((,temp (make-nearby-temp-file ,(format "git-%s" temp))))
1117 (unwind-protect (progn ,@body
1118 ;; This uses `file-local-name' to strip the
1119 ;; TRAMP prefix, not `file-relative-name',
1120 ;; because we've had at least one problem
1121 ;; report where relativizing the file name
1122 ;; meant that Git failed to find it.
1123 (vc-git-command nil 0 nil "apply" "--cached"
1124 (file-local-name ,temp)))
1125 (delete-file ,temp))))
1126
1114(defun vc-git-checkin (files comment &optional _rev) 1127(defun vc-git-checkin (files comment &optional _rev)
1115 (let* ((file1 (or (car files) default-directory)) 1128 (let* ((file1 (or (car files) default-directory))
1116 (root (vc-git-root file1)) 1129 (root (vc-git-root file1))
@@ -1194,8 +1207,7 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1194 (t (push file-name to-stash))) 1207 (t (push file-name to-stash)))
1195 (setq pos (point)))))) 1208 (setq pos (point))))))
1196 (unless (string-empty-p vc-git-patch-string) 1209 (unless (string-empty-p vc-git-patch-string)
1197 (let ((patch-file (make-nearby-temp-file "git-patch")) 1210 (let (;; Temporarily countermand the let-binding at the
1198 ;; Temporarily countermand the let-binding at the
1199 ;; beginning of this function. 1211 ;; beginning of this function.
1200 (coding-system-for-write 1212 (coding-system-for-write
1201 (coding-system-change-eol-conversion 1213 (coding-system-change-eol-conversion
@@ -1203,12 +1215,9 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1203 ;; to have the Unix EOL format, because Git expects 1215 ;; to have the Unix EOL format, because Git expects
1204 ;; that, even on Windows. 1216 ;; that, even on Windows.
1205 (or pcsw vc-git-commits-coding-system) 'unix))) 1217 (or pcsw vc-git-commits-coding-system) 'unix)))
1206 (with-temp-file patch-file 1218 (vc-git--with-apply-temp-to-staging patch
1207 (insert vc-git-patch-string)) 1219 (with-temp-file patch
1208 (unwind-protect 1220 (insert vc-git-patch-string)))))
1209 (vc-git-command nil 0 nil "apply" "--cached"
1210 (file-local-name patch-file))
1211 (delete-file patch-file))))
1212 (when to-stash (vc-git--stash-staged-changes to-stash))) 1221 (when to-stash (vc-git--stash-staged-changes to-stash)))
1213 (let ((files (and only (not vc-git-patch-string) files)) 1222 (let ((files (and only (not vc-git-patch-string) files))
1214 (args (vc-git--log-edit-extract-headers comment)) 1223 (args (vc-git--log-edit-extract-headers comment))
@@ -1218,15 +1227,9 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1218 (when (and msg-file (file-exists-p msg-file)) 1227 (when (and msg-file (file-exists-p msg-file))
1219 (delete-file msg-file)) 1228 (delete-file msg-file))
1220 (when to-stash 1229 (when to-stash
1221 (let ((cached (make-nearby-temp-file "git-cached"))) 1230 (vc-git--with-apply-temp-to-staging cached
1222 (unwind-protect 1231 (with-temp-file cached
1223 (progn 1232 (vc-git-command t 0 nil "stash" "show" "-p")))))))
1224 (with-temp-file cached
1225 (vc-git-command t 0 nil "stash" "show" "-p"))
1226 (vc-git-command nil 0 "apply" "--cached"
1227 (file-local-name cached)))
1228 (delete-file cached))
1229 (vc-git-command nil 0 nil "stash" "drop"))))))
1230 (when msg-file 1233 (when msg-file
1231 (let ((coding-system-for-write 1234 (let ((coding-system-for-write
1232 (or pcsw vc-git-commits-coding-system))) 1235 (or pcsw vc-git-commits-coding-system)))
@@ -1282,6 +1285,8 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1282 (unwind-protect 1285 (unwind-protect
1283 (progn 1286 (progn
1284 (vc-git-command nil 0 nil "read-tree" "HEAD") 1287 (vc-git-command nil 0 nil "read-tree" "HEAD")
1288 ;; See `vc-git--with-apply-temp-to-staging'
1289 ;; regarding use of `file-local-name'.
1285 (vc-git-command nil 0 nil "apply" "--cached" 1290 (vc-git-command nil 0 nil "apply" "--cached"
1286 (file-local-name cached)) 1291 (file-local-name cached))
1287 (setq tree (git-string "write-tree"))) 1292 (setq tree (git-string "write-tree")))