diff mbox series

[bug#63647,v2,2/3] guix: import: go: Catch Git error.

Message ID f699a25c43805136ada95ef7c7213a78abf5909e.1685029183.git.zimon.toutoune@gmail.com
State New
Headers show
Series [bug#63647,v2,1/3] guix: import: go: Sort hint about available versions. | expand

Commit Message

Simon Tournier May 25, 2023, 3:41 p.m. UTC
* guix/import/go.scm (git-checkout-hash): Catch Git error.

Reported-by: Felix Lechner <felix.lechner@lease-up.com>.
---
 guix/import/go.scm | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/guix/import/go.scm b/guix/import/go.scm
index 1943869162..c6258296f6 100644
--- a/guix/import/go.scm
+++ b/guix/import/go.scm
@@ -6,7 +6,7 @@ 
 ;;; Copyright © 2021-2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
-;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
+;;; Copyright © 2021, 2023 Simon Tournier <zimon.toutoune@gmail.com>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -36,9 +36,11 @@  (define-module (guix import go)
   #:use-module (guix memoization)
   #:use-module (guix utils)
   #:autoload   (htmlprag) (html->sxml)            ;from Guile-Lib
-  #:autoload   (guix base32) (bytevector->nix-base32-string)
+  #:autoload   (guix base32) (bytevector->nix-base32-string nix-base32-string->bytevector)
   #:autoload   (guix build utils) (mkdir-p)
+  #:autoload   (guix ui) (warning)
   #:autoload   (gcrypt hash) (hash-algorithm sha256)
+  #:autoload   (git structs) (git-error-message)
   #:use-module (ice-9 format)
   #:use-module (ice-9 match)
   #:use-module (ice-9 peg)
@@ -507,12 +509,18 @@  (define* (git-checkout-hash url reference algorithm)
   ;; subsequent "guix import" invocations.
   (mkdir-p cache)
   (chmod cache #o700)
-  (let-values (((checkout commit _)
-                (parameterize ((%repository-cache-directory cache))
-                  (update-cached-checkout url
-                                          #:ref
-                                          `(tag-or-commit . ,reference)))))
-    (file-hash* checkout #:algorithm algorithm #:recursive? #true)))
+  (catch 'git-error
+    (lambda _
+      (let-values (((checkout commit _)
+                    (parameterize ((%repository-cache-directory cache))
+                      (update-cached-checkout url
+                                              #:ref
+                                              `(tag-or-commit . ,reference)))))
+        (file-hash* checkout #:algorithm algorithm #:recursive? #true)))
+    (lambda (key error . rest)
+      (warning (G_ "Git error: ~a in ~a~%") (git-error-message error) url)
+      (nix-base32-string->bytevector
+       "0000000000000000000000000000000000000000000000000000"))))
 
 (define (vcs->origin vcs-type vcs-repo-url version)
   "Generate the `origin' block of a package depending on what type of source