aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean Whitton2024-10-21 09:44:20 +0800
committerSean Whitton2024-10-21 09:44:20 +0800
commit14624ff0fb7aec095a8846c3de5b089c93aa85da (patch)
tree1bd2a2bb00dbb8396d014850e29aba4dc81e60fe
parentfc6854cbd4733ef4247f5d9fd99d88d7b79c4dc4 (diff)
downloademacs-14624ff0fb7aec095a8846c3de5b089c93aa85da.tar.gz
emacs-14624ff0fb7aec095a8846c3de5b089c93aa85da.zip
; Undo WIP accidentally included in recent commit
-rw-r--r--lisp/vc/vc-git.el170
1 files changed, 28 insertions, 142 deletions
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index d2ada63f71e..f77bf0cc5ff 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -252,27 +252,6 @@ included in the completions."
252 :type 'boolean 252 :type 'boolean
253 :version "28.1") 253 :version "28.1")
254 254
255;; The default is nil because only a VC user who also possesses a lot of
256;; Git-specific knowledge can know when it is okay to rewrite history,
257;; and we can't convey to a relatively Git-naïve user the potential
258;; risks in only the space of a minibuffer y/n prompt.
259(defcustom vc-git-allow-rewriting-history nil
260 "When non-nil, permit Git operations that may rewrite published history.
261
262Many Git commands can change your copy of published change history
263without warning. If this occurs, you won't be able to pull and push in
264the ordinary way until you take special action. See \"Recovering from
265Upstream Rebase\" in the Man page git-rebase(1).
266
267Normally, Emacs refuses to run Git commands that it thinks will rewrite
268published history. If you customize this variable to a non-nil value,
269Emacs will instead prompt you to confirm that you really want to perform
270the rewrite. A value of `no-ask' means to proceed with no prompting."
271 :type '(choice (const :tag "Don't allow" nil)
272 (const :tag "Prompt to allow" t)
273 (const :tag "Allow without prompting" no-ask))
274 :version "31.1")
275
276;; History of Git commands. 255;; History of Git commands.
277(defvar vc-git-history nil) 256(defvar vc-git-history nil)
278 257
@@ -749,13 +728,11 @@ or an empty string if none."
749 :files files 728 :files files
750 :update-function update-function))) 729 :update-function update-function)))
751 730
752(defun vc-git--current-branch ()
753 (vc-git--out-match '("symbolic-ref" "HEAD")
754 "^\\(refs/heads/\\)?\\(.+\\)$" 2))
755
756(defun vc-git-dir--branch-headers () 731(defun vc-git-dir--branch-headers ()
757 "Return headers for branch-related information." 732 "Return headers for branch-related information."
758 (let ((branch (vc-git--current-branch)) 733 (let ((branch (vc-git--out-match
734 '("symbolic-ref" "HEAD")
735 "^\\(refs/heads/\\)?\\(.+\\)$" 2))
759 tracking remote-url) 736 tracking remote-url)
760 (if branch 737 (if branch
761 (when-let ((branch-merge 738 (when-let ((branch-merge
@@ -1105,17 +1082,6 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1105 1082
1106(autoload 'vc-switches "vc") 1083(autoload 'vc-switches "vc")
1107 1084
1108(defun vc-git--log-edit-extract-headers (comment)
1109 (cl-flet ((boolean-arg-fn (argument)
1110 (lambda (v) (and (equal v "yes") (list argument)))))
1111 (log-edit-extract-headers
1112 `(("Author" . "--author")
1113 ("Date" . "--date")
1114 ("Amend" . ,(boolean-arg-fn "--amend"))
1115 ("No-Verify" . ,(boolean-arg-fn "--no-verify"))
1116 ("Sign-Off" . ,(boolean-arg-fn "--signoff")))
1117 comment)))
1118
1119(defun vc-git-checkin (files comment &optional _rev) 1085(defun vc-git-checkin (files comment &optional _rev)
1120 (let* ((file1 (or (car files) default-directory)) 1086 (let* ((file1 (or (car files) default-directory))
1121 (root (vc-git-root file1)) 1087 (root (vc-git-root file1))
@@ -1214,23 +1180,31 @@ It is based on `log-edit-mode', and has Git-specific extensions."
1214 (vc-git-command nil 0 patch-file "apply" "--cached") 1180 (vc-git-command nil 0 patch-file "apply" "--cached")
1215 (delete-file patch-file)))) 1181 (delete-file patch-file))))
1216 (when to-stash (vc-git--stash-staged-changes files))) 1182 (when to-stash (vc-git--stash-staged-changes files)))
1217 ;; When operating on the whole tree, better pass "-a" than ".", 1183 (cl-flet ((boolean-arg-fn
1218 ;; since "." fails when we're committing a merge. 1184 (argument)
1219 (apply #'vc-git-command nil 0 1185 (lambda (value) (when (equal value "yes") (list argument)))))
1220 (if (and only (not vc-git-patch-string)) files) 1186 ;; When operating on the whole tree, better pass "-a" than ".", since "."
1221 (nconc (if msg-file (list "commit" "-F" 1187 ;; fails when we're committing a merge.
1222 (file-local-name msg-file)) 1188 (apply #'vc-git-command nil 0 (if (and only (not vc-git-patch-string)) files)
1223 (list "commit" "-m")) 1189 (nconc (if msg-file (list "commit" "-F"
1224 (let ((args 1190 (file-local-name msg-file))
1225 (vc-git--log-edit-extract-headers comment))) 1191 (list "commit" "-m"))
1226 (when msg-file 1192 (let ((args
1227 (let ((coding-system-for-write 1193 (log-edit-extract-headers
1228 (or pcsw vc-git-commits-coding-system))) 1194 `(("Author" . "--author")
1229 (write-region (car args) nil msg-file)) 1195 ("Date" . "--date")
1230 (setq args (cdr args))) 1196 ("Amend" . ,(boolean-arg-fn "--amend"))
1231 args) 1197 ("No-Verify" . ,(boolean-arg-fn "--no-verify"))
1232 (unless vc-git-patch-string 1198 ("Sign-Off" . ,(boolean-arg-fn "--signoff")))
1233 (if only (list "--only" "--") '("-a"))))) 1199 comment)))
1200 (when msg-file
1201 (let ((coding-system-for-write
1202 (or pcsw vc-git-commits-coding-system)))
1203 (write-region (car args) nil msg-file))
1204 (setq args (cdr args)))
1205 args)
1206 (unless vc-git-patch-string
1207 (if only (list "--only" "--") '("-a"))))))
1234 (if (and msg-file (file-exists-p msg-file)) (delete-file msg-file)) 1208 (if (and msg-file (file-exists-p msg-file)) (delete-file msg-file))
1235 (when to-stash 1209 (when to-stash
1236 (let ((cached (make-nearby-temp-file "git-cached"))) 1210 (let ((cached (make-nearby-temp-file "git-cached")))
@@ -1986,94 +1960,6 @@ This requires git 1.8.4 or later, for the \"-L\" option of \"git log\"."
1986 (vc-git-command standard-output 1 nil 1960 (vc-git-command standard-output 1 nil
1987 "log" "--max-count=1" "--pretty=format:%B" rev))) 1961 "log" "--max-count=1" "--pretty=format:%B" rev)))
1988 1962
1989(defun vc-git--assert-allowed-rewrite (rev)
1990 (when (and (not (eq vc-git-allow-rewriting-history 'no-ask))
1991 ;; Check there is an upstream.
1992 (with-temp-buffer
1993 (vc-git--out-ok "config" "--get"
1994 (format "branch.%s.merge"
1995 (vc-git--current-branch)))))
1996 (let ((outgoing (split-string
1997 (with-output-to-string
1998 (vc-git-command standard-output 0 nil "log"
1999 "--pretty=format:%H"
2000 "@{upstream}..HEAD")))))
2001 (unless (or (cl-member rev outgoing :test #'string-prefix-p)
2002 (and vc-git-allow-rewriting-history
2003 (yes-or-no-p
2004 (format
2005"Commit %s looks to be published; are you sure you want to rewrite history?"
2006 rev))))
2007 (user-error "Will not rewrite likely-public Git history")))))
2008
2009(defun vc-git-modify-change-comment (files rev comment)
2010 (vc-git--assert-allowed-rewrite rev)
2011 (let* ((args (delete "--amend"
2012 (vc-git--log-edit-extract-headers comment)))
2013 (message (format "amend! %s\n\n%s" rev (pop args)))
2014 (msg-file
2015 ;; On MS-Windows, pass the message through a file, to work
2016 ;; around how command line arguments must be in the system
2017 ;; codepage, and therefore might not support non-ASCII.
2018 ;;
2019 ;; As our other arguments are static, we need not be concerned
2020 ;; about the encoding of command line arguments in general.
2021 ;; See `vc-git-checkin' for the more complex case.
2022 (and (eq system-type 'windows-nt)
2023 (let ((default-directory
2024 (or (file-name-directory (or (car files)
2025 default-directory))
2026 default-directory)))
2027 (make-nearby-temp-file "git-msg"))))
2028 (nothing-staged
2029 (zerop
2030 (vc-git-command nil t nil "diff" "--cached" "--quiet"))))
2031 ;; We want to do just
2032 ;;
2033 ;; % git commit --only --allow-empty -m...
2034 ;; % git rebase --autostash --autosquash -i REV~1
2035 ;;
2036 ;; because the first command is guaranteed to create an empty commit
2037 ;; regardless of the state of the index and working tree. However,
2038 ;; that requires git.git commit 319d835, released in Git 2.11.1.
2039 ;; In order to support older Git we do this longer, slower sequence:
2040 ;;
2041 ;; % git stash push
2042 ;; % git commit --allow-empty -m...
2043 ;; % git rebase --autosquash -i REV~1
2044 ;; % git stash pop
2045 ;; (unless nothing-staged
2046 ;; (vc-git-command nil 0 nil "stash" "push"))
2047 (unwind-protect
2048 (progn
2049 (when (cl-intersection '("--author" "--date") args
2050 :test #'string=)
2051 ;; 'git rebase --autosquash' cannot alter authorship.
2052 ;; See the description of --fixup in git-commit(1).
2053 (error
2054"Author: and Date: not supported when modifying existing commits"))
2055 (when msg-file
2056 (let ((coding-system-for-write
2057 (or coding-system-for-write
2058 vc-git-commits-coding-system)))
2059 (write-region message nil msg-file)))
2060 (apply #'vc-git-command nil 0 nil
2061 "commit" "--allow-empty"
2062 (nconc (if msg-file
2063 (list "-F" (file-local-name msg-file))
2064 (list "-m" message))
2065 args)))
2066 (when (and msg-file (file-exists-p msg-file))
2067 ;; (delete-file msg-file)
2068 ))
2069 ;; (with-environment-variables (("GIT_SEQUENCE_EDITOR" "true"))
2070 ;; (vc-git-command nil 0 nil "rebase" "--autosquash" "-i"
2071 ;; (format "%s~1" rev)))
2072 ;; (unless nothing-staged
2073 ;; (vc-git-command nil 0 nil "stash" "pop" "--index"))
2074 (message "temporary file is: %s" msg-file)
2075 ))
2076
2077(defvar vc-git-extra-menu-map 1963(defvar vc-git-extra-menu-map
2078 (let ((map (make-sparse-keymap))) 1964 (let ((map (make-sparse-keymap)))
2079 (define-key map [git-grep] 1965 (define-key map [git-grep]