From 2078f83cc348c5b149fde1e4614ddc3e5b3d9b93 Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Tue, 28 Jan 2014 22:37:08 +0100 Subject: adds a --branch= option. The branchename is passed as BRANCH to the rockspec environment --- src/luarocks/command_line.lua | 7 +++++++ src/luarocks/fetch.lua | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/luarocks/command_line.lua b/src/luarocks/command_line.lua index 19d04290..f9fba300 100644 --- a/src/luarocks/command_line.lua +++ b/src/luarocks/command_line.lua @@ -113,6 +113,13 @@ function run_command(...) die("Invalid entry for --deps-mode.") end + if flags["branch"] then + if flags["branch"] == true or flags["branch"] == "" then + die("Argument error: use --branch=") + end + cfg.branch = flags["branch"] + end + if flags["tree"] then if flags["tree"] == true or flags["tree"] == "" then die("Argument error: use --tree=") diff --git a/src/luarocks/fetch.lua b/src/luarocks/fetch.lua index 7960acb4..e0525dde 100644 --- a/src/luarocks/fetch.lua +++ b/src/luarocks/fetch.lua @@ -144,10 +144,15 @@ end function load_local_rockspec(filename, quick) assert(type(filename) == "string") filename = fs.absolute_name(filename) - local rockspec, err = persist.load_into_table(filename) + local rockspec, err = persist.load_into_table(filename, {BRANCH = cfg.branch}) -- temp add BRANCH 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 + end local globals = err local ok, err = true, nil -- cgit v1.2.3-55-g6feb 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 From fd1d38a2d170deb9c7ffd0289a9bb97efac6f6ba Mon Sep 17 00:00:00 2001 From: Thijs Schreijer Date: Wed, 29 Jan 2014 21:43:12 +0100 Subject: added help info to build and make commands --- src/luarocks/build.lua | 4 ++++ src/luarocks/make.lua | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/luarocks/build.lua b/src/luarocks/build.lua index 72b5649e..0e58e2e5 100644 --- a/src/luarocks/build.lua +++ b/src/luarocks/build.lua @@ -32,6 +32,10 @@ or the name of a rock to be fetched from a repository. be made permanent by setting keep_other_versions=true in the configuration file. +--branch= Override the `source.branch` field in the loaded + rockspec. Allows to specify a different branch to + fetch. Particularly for SCM rocks. + ]]..util.deps_mode_help() --- Install files to a given location. diff --git a/src/luarocks/make.lua b/src/luarocks/make.lua index 3999e39f..af7e68e6 100644 --- a/src/luarocks/make.lua +++ b/src/luarocks/make.lua @@ -36,6 +36,10 @@ To install rocks, you'll normally want to use the "install" and be made permanent by setting keep_other_versions=true in the configuration file. +--branch= Override the `source.branch` field in the loaded + rockspec. Allows to specify a different branch to + fetch. Particularly for SCM rocks. + ]] --- Driver function for "make" command. -- cgit v1.2.3-55-g6feb