From 1e9edc66b768ad9e78401cf51931967430de1f7b Mon Sep 17 00:00:00 2001 From: mpeterv Date: Thu, 25 Jun 2015 14:14:16 +0300 Subject: Check that rockspec format is at least 3.0 before fetching submodules For utility, add deps.format_is_at_least(rockspec, version) function. --- src/luarocks/deps.lua | 9 +++++++++ src/luarocks/fetch/git.lua | 17 ++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/luarocks/deps.lua b/src/luarocks/deps.lua index 0e3265b5..f6c86d1c 100644 --- a/src/luarocks/deps.lua +++ b/src/luarocks/deps.lua @@ -159,6 +159,15 @@ function deps.compare_versions(a, b) return deps.parse_version(a) > deps.parse_version(b) end +--- Check if rockspec format version satisfies version requirement. +-- @param rockspec table: The rockspec table. +-- @param version string: required version. +-- @return boolean: true if rockspec format matches version or is newer, false otherwise. +function deps.format_is_at_least(rockspec, version) + local rockspec_format = rockspec.rockspec_format or "1.0" + return deps.parse_version(rockspec_format) >= deps.parse_version(version) +end + --- Consumes a constraint from a string, converting it to table format. -- For example, a string ">= 1.0, > 2.0" is converted to a table in the -- format {op = ">=", version={1,0}} and the rest, "> 2.0", is returned diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 0847f735..ce41659b 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -110,15 +110,18 @@ function git.get_sources(rockspec, extract, dest_dir, depth) end end - command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"} + -- Fetching git submodules is supported only when rockspec format is >= 3.0. + if deps.format_is_at_least(rockspec, "3.0") then + command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"} - if git_supports_shallow_submodules(git_cmd) then - -- Fetch only the last commit of each submodule. - table.insert(command, 5, "--depth=1") - end + if git_supports_shallow_submodules(git_cmd) then + -- Fetch only the last commit of each submodule. + table.insert(command, 5, "--depth=1") + end - if not fs.execute(unpack(command)) then - return nil, 'Failed to fetch submodules.' + if not fs.execute(unpack(command)) then + return nil, 'Failed to fetch submodules.' + end end fs.delete(dir.path(store_dir, module, ".git")) -- cgit v1.2.3-55-g6feb