Subject: [bug#77093] [PATCH rust-team 13/18] scripts: import: Skip existing definition for ‘--insert’ option.

From: Hilton Chain <[email-masked]>
Date: Tue, 18 Mar 2025 15:24:26 +0800

* guix/scripts/import.scm (guix-import): Skip existing definition for
‘--insert’ option.

Change-Id: I2c4242669f974b263a018ab0cf56538bd7c81d06
---
 guix/scripts/import.scm | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm
index 1b2c35f3b1..d8e1ed3e6f 100644
--- a/guix/scripts/import.scm
+++ b/guix/scripts/import.scm
@@ -137,16 +137,18 @@ (define-command (guix-import . args)
              (lambda (expr)
                (match expr
                  (((? definer? definer) term _ ...)
-                  (let ((source-properties
-                          (find-definition-insertion-location
+                  ;; Skip existing definition.
+                  (unless (find-definition-location file term #:definer definer)
+                    (let ((source-properties
+                           (find-definition-insertion-location
                             file term #:definer definer)))
-                    (if source-properties
-                      (insert-expression source-properties expr)
-                      (let ((port (open-file file "a")))
-                        (pretty-print-with-comments port expr)
-                        (newline port)
-                        (newline port)
-                        (close-port port)))))))))
+                      (if source-properties
+                          (insert-expression source-properties expr)
+                          (let ((port (open-file file "a")))
+                            (pretty-print-with-comments port expr)
+                            (newline port)
+                            (newline port)
+                            (close-port port))))))))))
        (import-as-definitions importer
                               (cons (string-append "--file-to-insert=" file)
                                     args)
-- 
2.48.1