Subject: [PATCH v2] git-download: Apply CR/LF to Git repository from SWH.

From: Simon Tournier <[email-masked]>
Date: Thu, 2 Mar 2023 13:05:46 +0100

From: Ludovic Courtès <[email-masked]>

Fixes a bug whereby CR/LF convention would not be applied on Git
repositories retrieved from SWH:

  https://sympa.inria.fr/sympa/arc/swh-devel/2023-03/msg00000.html

Reported by Simon Tournier <[email-masked]>.
Suggested by Valentin Lorentz <[email-masked]>.
Co-authored by Simon Tournier <[email-masked]>.

* guix/git-download.scm (git-fetch)[build]: Add Git operations conditioned by
.gitattributes on the result from SWH.
---
 guix/git-download.scm | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

Hi,

This uses 'flat' as previously but applies some Git commands for fixing CR/LF
when .gitattributes is present or not.  It works on the example hidapi.

I have not tried for other examples.

WDYT?

Cheers,
simon

diff --git a/guix/git-download.scm b/guix/git-download.scm
index a1566bed4d..be0b13615c 100644
--- a/guix/git-download.scm
+++ b/guix/git-download.scm
@@ -1,8 +1,9 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2014-2021, 2023 Ludovic Courtès <[email-masked]>
 ;;; Copyright © 2017 Mathieu Lirzin <[email-masked]>
 ;;; Copyright © 2017 Christopher Baines <[email-masked]>
 ;;; Copyright © 2020 Jakub Kądziołka <[email-masked]>
+;;; Copyright © 2023 Simon Tournier <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -162,8 +163,27 @@ (define recursive?
                      (parameterize ((%verify-swh-certificate? #f))
                        (format (current-error-port)
                                "Trying to download from Software Heritage...~%")
+
                        (swh-download (getenv "git url") (getenv "git commit")
-                                     #$output))))))))
+                                     #$output)
+                       ;; Perform CR/LF conversion if specificied by .gitattributes
+                       (when (find-files "." ".gitattributes")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "init")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "config" "--local" "user.email" "[email-masked]")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "config" "--local" "user.name" "Your Name")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "add" ".")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "commit" "-am" "'init'")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "read-tree" "--empty")
+                         (invoke #+(file-append git "/bin/git") "-C" #$output
+                                 "reset" "--hard")
+                         (delete-file-recursively
+                          (string-append #$output "/.git"))))))))))
 
   (mlet %store-monad ((guile (package->derivation guile system)))
     (gexp->derivation (or name "git-checkout") build

base-commit: af95f2d8f98eb2c8c64954bb2fd0b70838899174
-- 
2.38.1