Subject: Re: bug#77214: `guix pull` fails with `autocrlf=true` in git config

From: Simon Tournier <[email-masked]>
Date: Tue, 15 Apr 2025 18:15:48 +0200

Hi Ludo,

On Mon, 14 Apr 2025 at 23:09, Ludovic Courtès <[email-masked]> wrote:

>>    rm -rf ~/.cache/guix/checkouts
>>    git config --global core.autocrlf true
>>    ./pre-inst-env guix download --git \
>>       https://git.savannah.gnu.org/git/shepherd.git

This test does not catch the scenario leading to buggy behaviour, IMHO.

> Pushed as b5e567bb2b277f89af493ba8cd0799fdb368a184.  Thanks for testing!

This fixes appears to me incorrect.  Because it only fixes on a fresh
clone, when the typical scenario appears to me:

 1. I run Guix since months or years, no problem. \o/
 2. I work on a project with some collaborators running Windows.
 3. I add a global Git config.
 4. I run “guix pull“.  Bang!

Example:

--8<---------------cut here---------------start------------->8---
$ /tmp/new/bin/guix describe
Generation 1	Apr 15 2025 15:30:39	(current)
  guix b5e567b
    repository URL: https://git.savannah.gnu.org/git/guix.git
    commit: b5e567bb2b277f89af493ba8cd0799fdb368a184

$ git config --global core.autocrlf true

$ /tmp/new/bin/guix pull -q -p /tmp/last
Updating channel 'guix' from Git repository at 'https://git.savannah.gnu.org/git/guix.git'...
Authenticating channel 'guix', commits 9edb3f6 to ec5ea23 (29 new commits)...
Building from this channel:
  guix      https://git.savannah.gnu.org/git/guix.git	ec5ea23
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
substitute: updating substitutes from 'https://bordeaux.guix.gnu.org'... 100.0%
building /gnu/store/sggwz0vn6pldxnqfzgqaw4fx1rjkjwkj-config.scm.drv...
building /gnu/store/ybvdb767hk7ccilgmb3z4yl85xgw20sc-git.scm.drv...
building /gnu/store/fp8pld5b1b6sgbi9k1gwwrypynyi2n8g-hash.scm.drv...
applying 2 grafts for libffi-3.4.4 ...
applying 2 grafts for libgc-8.2.4 ...
applying 2 grafts for libunistring-1.1 ...
applying 2 grafts for pkg-config-0.29.2 ...
applying 7 grafts for guile-3.0.9 ...
building /gnu/store/c31lw8lmf2ncsbkpcqxwzzq01j1wb4ih-module-import.drv...
building /gnu/store/wdp91p4y3kcvjfrpq9das1na95qjlgnf-module-import.drv...
building /gnu/store/kvwl0ay9bb10fcibn96asnr73l4g2z4k-module-import-compiled.drv...
building /gnu/store/ify060g05i9rgxn15393yphnck775zb3-module-import-compiled.drv...
building /gnu/store/w89wb1k6139xj9k7ds4jqvzqx1qqc1b9-compute-guix-derivation.drv...
Computing Guix derivation for 'x86_64-linux'... /ice-9/read.scm:126:4: In procedure read-string:
gnu/packages/firmware.scm:1678:1: invalid character in escape sequence: #\return
guix pull: error: You found a bug: the program '/gnu/store/hqzmzshc0q3rbhcn2wpkm9xlf8sc6s8m-compute-guix-derivation'
failed to compute the derivation for Guix (version: "ec5ea239e9887f6ccf8aef0c9f9a6de9f72f7366"; system: "x86_64-linux";
host version: "b5e567bb2b277f89af493ba8cd0799fdb368a184"; pull-version: 1).
Please report the COMPLETE output above by email to <[email-masked]>.
--8<---------------cut here---------------end--------------->8---

Well, I have not found a way to tell to libgit2 to ignore *any*
configuration file [1].  Therefore, your fix seems the easiest.

However, the fix should be inside ’update-cached-checkout’.  It should
not be inside ’clone*’ because a) it does not fix potential annoyances
when people already cloned the repository – see above – and b) the issue
isn’t from the generic cloning but from cache management.

See the attached patch.  WDYT?

Cheers,
simon

>From 2f2b1af5f2c87671be06660bb8d8b6d2c9c3f6dd Mon Sep 17 00:00:00 2001
Message-ID: <2f2b1a[email-masked]>
From: Simon Tournier <[email-masked]>
Date: Tue, 15 Apr 2025 17:57:00 +0200
Subject: [PATCH] =?UTF-8?q?git:=20Move=20=E2=80=98core.autocrlf=E2=80=99?=
 =?UTF-8?q?=20settings.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Follow up of b5e567bb2b277f89af493ba8cd0799fdb368a184.

* guix/git.scm (clone*): Move ‘core.autocrlf’ settings from here...
(update-cached-checkout): ...to here.

Change-Id: I0f91d348376f9953cfbc497148596b738705818b
---
 guix/git.scm | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/guix/git.scm b/guix/git.scm
index 01e09185885..3965c61ba0b 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -241,12 +241,7 @@ (define* (clone* url directory #:key (verify-certificate? #t))
                      (make-clone-options
                       #:fetch-options (make-default-fetch-options
                                        #:verify-certificate?
-                                       verify-certificate?))))
-             (config (repository-config repository)))
-        ;; Override 'core.autocrlf' as set in ~/.gitconfig to ensure files are
-        ;; left unchanged when cloning and pulling.
-        (set-config-string config "core.autocrlf" "input")
-
+                                       verify-certificate?)))))
         repository))
     (lambda _
       (false-if-exception (rmdir directory)))))
@@ -606,7 +601,12 @@ (define* (update-cached-checkout url
                              (repository-open cache-directory)
                              (clone/swh-fallback url ref cache-directory
                                                  #:verify-certificate?
-                                                 verify-certificate?))))
+                                                 verify-certificate?)))
+          (config (repository-config repository)))
+     ;; Override 'core.autocrlf' as set in ~/.gitconfig to ensure files are
+     ;; left unchanged when cloning and pulling.
+     (set-config-string config "core.autocrlf" "input")
+
      ;; Only fetch remote if it has not been cloned just before.
      (when (and cache-exists?
                 (not (reference-available? repository ref)))

base-commit: ec5ea239e9887f6ccf8aef0c9f9a6de9f72f7366
-- 
2.46.0

- - -
1: bug#77214: `guix pull` fails with `autocrlf=true` in git config
Simon Tournier <[email-masked]>
Fri, 11 Apr 2025 19:14:17 +0200
id:[email-masked]
https://issues.guix.gnu.org/77214
https://issues.guix.gnu.org/msgid/[email-masked]
https://yhetil.org/guix/[email-masked]

PS: From my understanding, this change does not deserve Copyright.  I
    know your optimistic idea: maybe you will change again and then
    maybe again this file, so then the Copyright applies. :-) I still
    think we should keep the “rule” of non-trivial change which means
    more or less 5+ lines modified.  For what my opinion is worth
    here. :-)