Subject: [PATCH v2 2/3] import: utils: Add predicates for checking VCS repositories.

From: Xinglu Chen <[email-masked]>
Date: Sun, 04 Jul 2021 13:54:18 +0200

* guix/import/utils.scm (git-repository?, hg-repository?): New procedures.
---
 guix/import/utils.scm | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/guix/import/utils.scm b/guix/import/utils.scm
index d817318a91..bcf26ae363 100644
--- a/guix/import/utils.scm
+++ b/guix/import/utils.scm
@@ -8,6 +8,7 @@
 ;;; Copyright © 2020 Helio Machado <[email-masked]>
 ;;; Copyright © 2020 Martin Becze <[email-masked]>
 ;;; Copyright © 2021 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2021 Xinglu Chen <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -43,6 +44,7 @@
   #:use-module (ice-9 rdelim)
   #:use-module (ice-9 receive)
   #:use-module (ice-9 regex)
+  #:use-module (ice-9 ftw)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-9)
   #:use-module (srfi srfi-11)
@@ -74,6 +76,9 @@
 
             guix-name
 
+            git-repository?
+            hg-repository?
+            
             recursive-import))
 
 (define (factorize-uri uri version)
@@ -422,6 +427,16 @@ separated by PRED."
                                       (chr (char-downcase chr)))
                                     name)))
 
+(define (git-repository? directory)
+  "Check whether DIRECTORY is a Git repository."
+  (let ((contents (scandir directory)))
+    (if (member ".git" contents) #t #f)))
+
+(define (hg-repository? directory)
+  "Check whether DIRECTORY is a Hg repository."
+  (let ((contents (scandir directory)))
+    (if (member ".hg" contents) #t #f)))
+
 (define (topological-sort nodes
                           node-dependencies
                           node-name)
-- 
2.32.0