From d0aab1fa942409150e242cca18029debf547af9e Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 29 Jan 2014 21:03:20 +0100 Subject: updated the `--branch` option to work through updating the rockspec `source.branch` field Additionally a fix for the `git` module, to use command quoting --- src/luarocks/fetch.lua | 8 +++----- src/luarocks/fetch/git.lua | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index e0525dde..8e08e7ad 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -144,14 +144,12 @@ end function load_local_rockspec(filename, quick) assert(type(filename) == "string") filename = fs.absolute_name(filename) - local rockspec, err = persist.load_into_table(filename, {BRANCH = cfg.branch}) -- temp add BRANCH + local rockspec, err = persist.load_into_table(filename) if not rockspec then return nil, "Could not load rockspec file "..filename.." ("..err..")" end - if rockspec.BRANCH ~= cfg.branch then - return nil, "Invalid rockspec, BRANCH constant was illegally modified by rockspec" - else - rockspec.BRANCH = nil -- remove temporary added field + if cfg.branch and (type(rockspec.source) == "table") then + rockspec.source.branch = cfg.branch end local globals = err diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua index 1845363f..2bba4cdc 100644 --- a/src/luarocks/fetch/git.lua +++ b/src/luarocks/fetch/git.lua @@ -12,7 +12,7 @@ local util = require("luarocks.util") -- given tag. -- @return boolean: Whether Git can clone by tag. local function git_can_clone_by_tag(git_cmd) - local version_string = io.popen(git_cmd..' --version'):read() + local version_string = io.popen(fs.Q(git_cmd)..' --version'):read() local major, minor, tiny = version_string:match('(%d-)%.(%d+)%.?(%d*)') major, minor, tiny = tonumber(major), tonumber(minor), tonumber(tiny) or 0 local value = major > 1 or (major == 1 and (minor > 7 or (minor == 7 and tiny >= 10))) @@ -51,7 +51,7 @@ function get_sources(rockspec, extract, dest_dir, depth) local ok, err = fs.change_dir(store_dir) if not ok then return nil, err end - local command = {git_cmd, "clone", depth or "--depth=1", rockspec.source.url, module} + local command = {fs.Q(git_cmd), "clone", depth or "--depth=1", rockspec.source.url, module} local tag_or_branch = rockspec.source.tag or rockspec.source.branch -- If the tag or branch is explicitly set to "master" in the rockspec, then -- we can avoid passing it to Git since it's the default. @@ -69,7 +69,7 @@ function get_sources(rockspec, extract, dest_dir, depth) local ok, err = fs.change_dir(module) if not ok then return nil, err end if tag_or_branch and not git_can_clone_by_tag() then - local checkout_command = {git_cmd, "checkout", tag_or_branch} + local checkout_command = {fs.Q(git_cmd), "checkout", tag_or_branch} if not fs.execute(unpack(checkout_command)) then return nil, 'Failed to check out the "' .. tag_or_branch ..'" tag or branch.' end -- cgit v1.2.3-55-g6feb