aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Tammela <pctammela@gmail.com>2019-12-14 16:37:19 -0300
committerHisham Muhammad <hisham@gobolinux.org>2019-12-17 15:47:50 -0300
commit914b831271099e0f25cd9c1af66d354c5ee64ed2 (patch)
tree9aac2741673f31126d058391f80422fe3fbeeb4d
parent129ebf34efa945b2b56a29c80b161414a98757a8 (diff)
downloadluarocks-914b831271099e0f25cd9c1af66d354c5ee64ed2.tar.gz
luarocks-914b831271099e0f25cd9c1af66d354c5ee64ed2.tar.bz2
luarocks-914b831271099e0f25cd9c1af66d354c5ee64ed2.zip
git: add support for shallow recommendations
In more recent versions of git, the .gitmodules file can be configured to recommend if a submodule should be cloned as shallow or not. Add support for this feature since it gives the rock maintainer more control over which submodules should be shallow cloned. The rock maintainer may set the boolean `shallow` to true or false in .gitmodules. If omitted it is treated as false. Signed-off-by: Pedro Tammela <pctammela@gmail.com>
-rw-r--r--src/luarocks/fetch/git.lua11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index 49ee7183..88ba4848 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -50,6 +50,13 @@ local function git_supports_shallow_submodules(git_cmd)
50 return git_is_at_least(git_cmd, "1.8.4") 50 return git_is_at_least(git_cmd, "1.8.4")
51end 51end
52 52
53--- Git >= 2.10 can fetch submodules shallowly according to .gitmodules configuration, allowing more granularity.
54-- @param git_cmd string: name of git command.
55-- @return boolean: Whether Git can fetch submodules shallowly according to .gitmodules.
56local function git_supports_shallow_recommendations(git_cmd)
57 return git_is_at_least(git_cmd, "2.10.0")
58end
59
53local function git_identifier(git_cmd, ver) 60local function git_identifier(git_cmd, ver)
54 if not (ver:match("^dev%-%d+$") or ver:match("^scm%-%d+$")) then 61 if not (ver:match("^dev%-%d+$") or ver:match("^scm%-%d+$")) then
55 return nil 62 return nil
@@ -132,7 +139,9 @@ function git.get_sources(rockspec, extract, dest_dir, depth)
132 if rockspec:format_is_at_least("3.0") then 139 if rockspec:format_is_at_least("3.0") then
133 command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"} 140 command = {fs.Q(git_cmd), "submodule", "update", "--init", "--recursive"}
134 141
135 if git_supports_shallow_submodules(git_cmd) then 142 if git_supports_shallow_recommendations(git_cmd) then
143 table.insert(command, 5, "--recommend-shallow")
144 elseif git_supports_shallow_submodules(git_cmd) then
136 -- Fetch only the last commit of each submodule. 145 -- Fetch only the last commit of each submodule.
137 table.insert(command, 5, "--depth=1") 146 table.insert(command, 5, "--depth=1")
138 end 147 end