Function: vc-git-modify-change-comment

vc-git-modify-change-comment is a byte-compiled function defined in vc-git.el.gz.

Signature

(vc-git-modify-change-comment FILES REV COMMENT)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/vc-git.el.gz
(defun vc-git-modify-change-comment (files rev comment)
  (vc-git--assert-allowed-rewrite rev)
  (when (zerop (vc-git--call nil nil "rev-parse" (format "%s^2" rev)))
    ;; This amend! approach doesn't work for merge commits.
    ;; Error out now instead of leaving an amend! commit hanging.
    (error "Cannot modify merge commit comments"))
  (let* ((args (delete "--amend"
                       (vc-git--log-edit-extract-headers comment)))
         (message (format "amend! %s\n\n%s" rev (pop args)))
         (msg-file
          ;; On MS-Windows, pass the message through a file, to work
          ;; around how command line arguments must be in the system
          ;; codepage, and therefore might not support non-ASCII.
          (and (eq system-type 'windows-nt)
               (let ((default-directory
                      (or (file-name-directory (or (car files)
                                                   default-directory))
                          default-directory)))
                 (make-nearby-temp-file "git-msg")))))
    (unwind-protect
        (progn
          (when (cl-intersection '("--author" "--date") args
                                 :test #'string=)
            ;; 'git rebase --autosquash' cannot alter authorship.
            ;; See the description of --fixup in git-commit(1).
            (error
"Author: and Date: not supported when modifying existing commits"))

          ;; Check that a rebase with --autosquash won't make changes
          ;; other than to REV's change comment.  With the prompt here
          ;; it's okay to assume the user knows what --autosquash is
          ;; because they've made some squash!/fixup!/amend! commits.
          (when
              (and (split-string
                    (with-output-to-string
                      (vc-git-command standard-output 0 nil
                                      "log" "--oneline" "-E"
                                      "--grep" "^(squash|fixup|amend)! "
                                      (format "%s~1.." rev))))
                   (not (yes-or-no-p "\
Rebase may --autosquash your other squash!/fixup!/amend!; proceed?")))
            (user-error "Aborted"))

          (when msg-file
            (let ((coding-system-for-write
                   (or coding-system-for-write
                       vc-git-commits-coding-system)))
              (write-region message nil msg-file)))
          ;; Regardless of the state of the index and working tree, this
          ;; will always create an empty commit, thanks to --only.
          (let ((coding-system-for-write
                 ;; On MS-Windows, we must encode command-line arguments in
                 ;; the system codepage.
                 (if (eq system-type 'windows-nt)
                     locale-coding-system
                   coding-system-for-write)))
            (apply #'vc-git-command nil 0 nil
                   "commit" "--only" "--allow-empty"
                   (nconc (if msg-file
                              (list "-F" (file-local-name msg-file))
                            (list "-m" message))
                          args))))
      (when (and msg-file (file-exists-p msg-file))
        (delete-file msg-file))))
  (with-environment-variables (("GIT_SEQUENCE_EDITOR" "true"))
    (vc-git-command nil 0 nil "rebase" "--autostash" "--autosquash" "-i"
                    (format "%s~1" rev))))