Subject: Re: bug#30428: guix git-fetch doesn't specify "--depth 1" - git clone clones a lot without any use

From: Danny Milosavljevic <[email-masked]>
Date: Mon, 12 Feb 2018 23:59:50 +0100

Hi Leo,

On Mon, 12 Feb 2018 10:09:39 -0500
Leo Famulari <[email-masked]> wrote:

> I think it's worth adding, but as an option, because there are Git
> server implementations, like JGit, that don't support shallow cloning.

Thanks for that!  I didn't consider that before...

Possible patch (do you know such servers and can test whether they still work?):

diff --git a/guix/build/git.scm b/guix/build/git.scm
index c1af545a7..e54d92be7 100644
--- a/guix/build/git.scm
+++ b/guix/build/git.scm
@@ -37,12 +37,18 @@ recursively.  Return #t on success, #f otherwise."
   ;; in advance anyway.
   (setenv "GIT_SSL_NO_VERIFY" "true")
 
+  (mkdir-p directory)
+
   ;; We cannot use "git clone --recursive" since the following "git checkout"
   ;; effectively removes sub-module checkouts as of Git 2.6.3.
-  (and (zero? (system* git-command "clone" url directory))
+  (and ;(zero? (system* git-command "clone" url directory))
        (with-directory-excursion directory
-         (system* git-command "tag" "-l")
-         (and (zero? (system* git-command "checkout" commit))
+         ;(system* git-command "tag" "-l")
+         (invoke git-command "init")
+         (invoke git-command "remote" "add" "origin" url)
+         (and (or (zero? (system* git-command "fetch" "--depth" "1" "origin" commit))
+                  (zero? (system* git-command "fetch" "origin" commit)))
+              (zero? (system* git-command "checkout" "FETCH_HEAD"))
               (begin
                 (when recursive?
                   ;; Now is the time to fetch sub-modules.