Subject: bug#64055: Implementation of modifying VC change comments for Git

From: Sean Whitton <[email-masked]>
Date: Sun, 20 Oct 2024 16:59:32 +0800

Hello,

On Sun 20 Oct 2024 at 11:32am +03, Eli Zaretskii wrote:

> So someone will have to test the patch on Windows with a new en ough
> Git version.

I don't think so -- the code to support Windows is independent of the
code to support older Git.  So, my tests here on GNU/Linux with newer
Git, together with yours on Windows with older Git, are sufficient.

>> I think we can support older by stashing and unstashing.  So please try
>> the attached patch, which does that.
>
> This seems to work without any errors, and the *vc* buffer says
>
>   Successfully rebased and updated refs/heads/master.
>
> But the log message is not updated, neither in the *vc-change-log*
> buffer nor if I manually invoke "git log" from the shell prompt.  It
> sounds like the commit message was not amended.  "git stash list" also
> shows no relevant stashes.
>
> Let me know how can I help you debug this.

Thank you for testing it.

Let's try commenting out everything except the 'git commit', as done in
the following diff on top of my patch.  Please test this without
anything staged.  Does it create a new commit at the tip of your branch?

The contents of the commit should be a special first line, followed by
your amended commit message.

If not: I've also commented out the deletion of the temporary file, and
sent its name to *Messages*.  If you look in that temporary file, do you
find your amended commit message?

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 59d5386bc72..d2ada63f71e 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -2042,8 +2042,8 @@ vc-git-modify-change-comment
     ;;     % git commit --allow-empty -m...
     ;;     % git rebase --autosquash -i REV~1
     ;;     % git stash pop
-    (unless nothing-staged
-      (vc-git-command nil 0 nil "stash" "push"))
+    ;; (unless nothing-staged
+    ;;   (vc-git-command nil 0 nil "stash" "push"))
     (unwind-protect
         (progn
           (when (cl-intersection '("--author" "--date") args
@@ -2064,12 +2064,15 @@ vc-git-modify-change-comment
                           (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" "--autosquash" "-i"
-                      (format "%s~1" rev)))
-    (unless nothing-staged
-      (vc-git-command nil 0 nil "stash" "pop" "--index"))))
+        ;; (delete-file msg-file)
+        ))
+    ;; (with-environment-variables (("GIT_SEQUENCE_EDITOR" "true"))
+    ;;   (vc-git-command nil 0 nil "rebase" "--autosquash" "-i"
+    ;;                   (format "%s~1" rev)))
+    ;; (unless nothing-staged
+    ;;   (vc-git-command nil 0 nil "stash" "pop" "--index"))
+    (message "temporary file is: %s" msg-file)
+    ))

 (defvar vc-git-extra-menu-map
   (let ((map (make-sparse-keymap)))
--8<---------------cut here---------------end--------------->8---

-- 
Sean Whitton