From 56c0b2a45c2c31d14a07dc684e2193447cd2e2e7 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 31 Aug 2023 00:41:32 +0800 Subject: improve shallow submodules --- xmake/modules/devel/git/clone.lua | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'xmake/modules/devel/git/clone.lua') diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua index 469d36c2e..a1e7ca8eb 100644 --- a/xmake/modules/devel/git/clone.lua +++ b/xmake/modules/devel/git/clone.lua @@ -38,6 +38,20 @@ function can_clone_tag() return can or false end +-- can clone with --shallow-submodules? +-- @see https://github.com/xmake-io/xmake/issues/4151 +function can_shallow_submodules() + local can = _g.can_shallow_submodules + if can == nil then + local git = assert(find_tool("git", {version = true}), "git not found!") + if git.version and semver.compare(git.version, "2.9.0") >= 0 then + can = true + end + _g.can_shallow_submodules = can or false + end + return can or false +end + -- clone url -- -- @param url the git url @@ -82,7 +96,7 @@ function main(url, opt) if opt.recurse_submodules then table.insert(argv, "--recurse-submodules") end - if opt.shallow_submodules then + if opt.shallow_submodules and can_shallow_submodules() then table.insert(argv, "--shallow-submodules") end -- cgit v1.3.1