commit 28371be86f02bf25a98115ae79c19a46625ca094 Author: Thomas Harning Jr <...> Date: Sun Aug 17 17:29:59 2008 -0400 fetch: added preliminary support for fetching 'git' over the git:// protocol (missing git+ssh, git+http) diff --git a/Makefile b/Makefile index 0c505f5..5831eed 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ command_line.lua cfg.lua deps.lua fetch.lua fs.lua fs/unix.lua \ fs/win32.lua help.lua install.lua list.lua persist.lua \ make_manifest.lua pack.lua path.lua rep.lua require.lua search.lua \ type_check.lua util.lua remove.lua build/builtin.lua make.lua manif.lua unpack.lua \ -fetch/cvs.lua fetch/sscm.lua +fetch/cvs.lua fetch/sscm.lua fetch/git.lua CONFIG_FILE = $(SYSCONFDIR)/config.lua diff --git a/src/luarocks/fetch/git.lua b/src/luarocks/fetch/git.lua new file mode 100644 index 0000000..61d68b3 --- /dev/null +++ b/src/luarocks/fetch/git.lua @@ -0,0 +1,53 @@ + +--- Fetch back-end for retrieving sources from GIT. +module("luarocks.fetch.git", package.seeall) + +local fs = require("luarocks.fs") +local util = require("luarocks.util") + +--- Download sources for building a rock, using git. +-- @param rockspec table: The rockspec table +-- @param extract boolean: Unused in this module (required for API purposes.) +-- @param dest_dir string or nil: If set, will extract to the given directory. +-- @return (string, string) or (nil, string): The absolute pathname of +-- the fetched source tarball and the temporary directory created to +-- store it; or nil and an error message. +function get_sources(rockspec, extract, dest_dir) + assert(type(rockspec) == "table") + assert(type(dest_dir) == "string" or not dest_dir) + + local name_version = rockspec.name .. "-" .. rockspec.version + local module = fs.base_name(rockspec.source.url) + -- Strip off .git from base name if present + module = module:gsub("%.git$", "") + local command = {"git", "clone", rockspec.source.url, module} + local checkoutCommand + local tagOrBranch = rockspec.source.tag or rockspec.source.branch + if tagOrBranch then + checkoutCommand = {"git", "checkout", tagOrBranch} + end + local dir + if not dest_dir then + dir = fs.make_temp_dir(name_version) + if not dir then + return nil, "Failed creating temporary directory." + end + util.schedule_function(fs.delete, dir) + else + dir = dest_dir + end + fs.change_dir(dir) + if not fs.execute(unpack(command)) then + return nil, "Failed fetching files from GIT while cloning." + end + if checkoutCommand then + fs.change_dir(module) + if not fs.execute(unpack(checkoutCommand)) then + return nil, "Failed fetching files from GIT while getting tag/branch." + end + fs.pop_dir() + end + fs.pop_dir() + return module, dir +end +