aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/luarocks/cfg.lua3
-rw-r--r--src/luarocks/fetch/git.lua41
-rw-r--r--src/luarocks/fetch/svn.lua7
-rw-r--r--src/luarocks/fs/lua.lua2
4 files changed, 44 insertions, 9 deletions
diff --git a/src/luarocks/cfg.lua b/src/luarocks/cfg.lua
index 56a9a965..48b40586 100644
--- a/src/luarocks/cfg.lua
+++ b/src/luarocks/cfg.lua
@@ -1,4 +1,3 @@
1
2--- Configuration for LuaRocks. 1--- Configuration for LuaRocks.
3-- Tries to load the user's configuration file and 2-- Tries to load the user's configuration file and
4-- defines defaults for unset values. See the 3-- defines defaults for unset values. See the
@@ -26,7 +25,7 @@ end
26_M.site_config = site_config 25_M.site_config = site_config
27 26
28lua_version = _VERSION:sub(5) 27lua_version = _VERSION:sub(5)
29program_version = "2.0.8" 28program_version = "2.0.9"
30user_agent = "LuaRocks/"..program_version 29user_agent = "LuaRocks/"..program_version
31 30
32local persist = require("luarocks.persist") 31local persist = require("luarocks.persist")
diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua
index e5f1ad4d..d643d25d 100644
--- a/src/luarocks/fetch/git.lua
+++ b/src/luarocks/fetch/git.lua
@@ -6,6 +6,20 @@ local fs = require("luarocks.fs")
6local dir = require("luarocks.dir") 6local dir = require("luarocks.dir")
7local util = require("luarocks.util") 7local util = require("luarocks.util")
8 8
9--- Git >= 1.7.10 can clone a branch **or tag**, < 1.7.10 by branch only. We
10-- need to know this in order to build the appropriate command; if we can't
11-- clone by tag then we'll have to issue a subsequent command to check out the
12-- given tag.
13-- @return boolean: Whether Git can clone by tag.
14local function git_can_clone_by_tag()
15 local version_string = io.popen('git --version'):read()
16 local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)')
17 major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0
18 value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10)))
19 git_can_clone_by_tag = function() return value end
20 return git_can_clone_by_tag()
21end
22
9--- Download sources for building a rock, using git. 23--- Download sources for building a rock, using git.
10-- @param rockspec table: The rockspec table 24-- @param rockspec table: The rockspec table
11-- @param extract boolean: Unused in this module (required for API purposes.) 25-- @param extract boolean: Unused in this module (required for API purposes.)
@@ -22,11 +36,7 @@ function get_sources(rockspec, extract, dest_dir)
22 local module = dir.base_name(rockspec.source.url) 36 local module = dir.base_name(rockspec.source.url)
23 -- Strip off .git from base name if present 37 -- Strip off .git from base name if present
24 module = module:gsub("%.git$", "") 38 module = module:gsub("%.git$", "")
25 local command = {git_cmd, "clone", "--depth=1", rockspec.source.url, module} 39
26 local tag_or_branch = rockspec.source.tag or rockspec.source.branch
27 if tag_or_branch then
28 table.insert(command, 4, "--branch=" .. tag_or_branch)
29 end
30 local store_dir 40 local store_dir
31 if not dest_dir then 41 if not dest_dir then
32 store_dir = fs.make_temp_dir(name_version) 42 store_dir = fs.make_temp_dir(name_version)
@@ -39,14 +49,33 @@ function get_sources(rockspec, extract, dest_dir)
39 end 49 end
40 store_dir = fs.absolute_name(store_dir) 50 store_dir = fs.absolute_name(store_dir)
41 fs.change_dir(store_dir) 51 fs.change_dir(store_dir)
52
53 local command = {git_cmd, "clone", "--depth=1", rockspec.source.url, module}
54 local tag_or_branch = rockspec.source.tag or rockspec.source.branch
55 -- If the tag or branch is explicitly set to "master" in the rockspec, then
56 -- we can avoid passing it to Git since it's the default.
57 if tag_or_branch == "master" then tag_or_branch = nil end
58 if tag_or_branch then
59 if git_can_clone_by_tag() then
60 -- The argument to `--branch` can actually be a branch or a tag as of
61 -- Git 1.7.10.
62 table.insert(command, 4, "--branch=" .. tag_or_branch)
63 end
64 end
42 if not fs.execute(unpack(command)) then 65 if not fs.execute(unpack(command)) then
43 return nil, "Failed cloning git repository." 66 return nil, "Failed cloning git repository."
44 end 67 end
45 fs.change_dir(module) 68 fs.change_dir(module)
69 if tag_or_branch and not git_can_clone_by_tag() then
70 local checkout_command = {git_cmd, "checkout", tag_or_branch}
71 if not fs.execute(unpack(checkout_command)) then
72 return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.'
73 end
74 end
75
46 fs.delete(dir.path(store_dir, module, ".git")) 76 fs.delete(dir.path(store_dir, module, ".git"))
47 fs.delete(dir.path(store_dir, module, ".gitignore")) 77 fs.delete(dir.path(store_dir, module, ".gitignore"))
48 fs.pop_dir() 78 fs.pop_dir()
49 fs.pop_dir() 79 fs.pop_dir()
50 return module, store_dir 80 return module, store_dir
51end 81end
52
diff --git a/src/luarocks/fetch/svn.lua b/src/luarocks/fetch/svn.lua
index 9d00ce5b..a4e952d2 100644
--- a/src/luarocks/fetch/svn.lua
+++ b/src/luarocks/fetch/svn.lua
@@ -40,6 +40,13 @@ function get_sources(rockspec, extract, dest_dir)
40 if not fs.execute(unpack(command)) then 40 if not fs.execute(unpack(command)) then
41 return nil, "Failed fetching files from Subversion." 41 return nil, "Failed fetching files from Subversion."
42 end 42 end
43 fs.change_dir(module)
44 for _, d in ipairs(fs.find(".")) do
45 if dir.base_name(d) == ".svn" then
46 fs.delete(dir.path(store_dir, module, d))
47 end
48 end
49 fs.pop_dir()
43 fs.pop_dir() 50 fs.pop_dir()
44 return module, store_dir 51 return module, store_dir
45end 52end
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua
index 67c3ce0f..09175758 100644
--- a/src/luarocks/fs/lua.lua
+++ b/src/luarocks/fs/lua.lua
@@ -247,7 +247,7 @@ function copy(src, dest, perms)
247 if not perms then perms = fs.get_permissions(src) end 247 if not perms then perms = fs.get_permissions(src) end
248 local src_h, err = io.open(src, "rb") 248 local src_h, err = io.open(src, "rb")
249 if not src_h then return nil, err end 249 if not src_h then return nil, err end
250 local dest_h, err = io.open(dest, "wb+") 250 local dest_h, err = io.open(dest, "w+b")
251 if not dest_h then src_h:close() return nil, err end 251 if not dest_h then src_h:close() return nil, err end
252 while true do 252 while true do
253 local block = src_h:read(8192) 253 local block = src_h:read(8192)