From 7d554f295ca0a8947042f367adb4f198730696be Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 1 Jul 2020 14:57:59 +0200 Subject: [PATCH] Support building flakes from a shallow Git repo Fixes #3756. --- src/libexpr/flake/flakeref.cc | 3 +++ src/libfetchers/git.cc | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/libexpr/flake/flakeref.cc b/src/libexpr/flake/flakeref.cc index 615269218..701546671 100644 --- a/src/libexpr/flake/flakeref.cc +++ b/src/libexpr/flake/flakeref.cc @@ -142,6 +142,9 @@ std::pair parseFlakeRefWithFragment( parsedURL.query.insert_or_assign("dir", subdir); } + if (pathExists(flakeRoot + "/.git/shallow")) + parsedURL.query.insert_or_assign("shallow", "1"); + return std::make_pair( FlakeRef(Input::fromURL(parsedURL), get(parsedURL.query, "dir").value_or("")), fragment); diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 0b6155e71..5d38e0c2b 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -42,6 +42,8 @@ struct GitInputScheme : InputScheme for (auto &[name, value] : url.query) { if (name == "rev" || name == "ref") attrs.emplace(name, value); + else if (name == "shallow") + attrs.emplace(name, Explicit { value == "1" }); else url2.query.emplace(name, value); }