Subject: Re: bug#68377: Cannot commit parts of *vc-diff* on Microsoft Windows

From: Eli Zaretskii <[email-masked]>
Date: Thu, 11 Jan 2024 14:44:41 +0200

> Cc: [email-masked]
> Date: Thu, 11 Jan 2024 14:28:49 +0200
> From: Eli Zaretskii <[email-masked]>
> 
> > # work-around 1
> > 
> > Add 
> > ```
> > (setq coding-system-for-write 'utf-8-unix)
> > ```
> > inside `(with-temp-file patch-file ...)` in `vc-git-checkin`
> 
> The code in question already does:
> 
>         (let ((patch-file (make-nearby-temp-file "git-patch"))
>               ;; Temporarily countermand the let-binding at the
>               ;; beginning of this function.
>               (coding-system-for-write
>                (coding-system-change-eol-conversion
>                 ;; On DOS/Windows, it is important for the patch file
>                 ;; to have the Unix EOL format, because Git expects
>                 ;; that, even on Windows.
>                 (or pcsw vc-git-commits-coding-system) 'unix)))
>           (with-temp-file patch-file
>             (insert vc-git-patch-string))
> 
> So coding-system-for-write should already be -unix when with-temp-file
> runs.  I guess there's more here than meets the eye, or maybe I'm
> missing something.

And sure enough, trying the recipe from "emacs -Q" fails to reproduce
the problem.  So there's something else at work here.

Could you please try this in "emacs -Q"?  If it doesn't work in
"emacs -Q", please step in Edebug through vc-git-checkin and tell
what you see as the value of coding-system-for-write when this code
is executed:

          (with-temp-file patch-file
            (insert vc-git-patch-string))

and also what is the EOL format of patch-file that Emacs creates
there, and let's take it from there.

If this does work in "emacs -Q", then some of your customizations
related to coding-systems probably get in the way.

FTR, in my case autocrlf is also false (as it should be).