diff options
Diffstat (limited to 'xmake/modules/devel/git')
| -rw-r--r-- | xmake/modules/devel/git/checkout.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clean.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/devel/git/ls_remote.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/devel/git/submodule/update.lua | 77 |
6 files changed, 100 insertions, 1 deletions
diff --git a/xmake/modules/devel/git/checkout.lua b/xmake/modules/devel/git/checkout.lua index 12541e5ac..4a4c92bae 100644 --- a/xmake/modules/devel/git/checkout.lua +++ b/xmake/modules/devel/git/checkout.lua @@ -38,6 +38,9 @@ import("lib.detect.find_tool") -- function main(commit, opt) + -- init options + opt = opt or {} + -- find git local git = find_tool("git") if not git then diff --git a/xmake/modules/devel/git/clean.lua b/xmake/modules/devel/git/clean.lua index 2d80c2bac..4ed39a20f 100644 --- a/xmake/modules/devel/git/clean.lua +++ b/xmake/modules/devel/git/clean.lua @@ -37,6 +37,9 @@ import("lib.detect.find_tool") -- function main(opt) + -- init options + opt = opt or {} + -- find git local git = find_tool("git") if not git then diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua index 75a652b1d..4a77abbf5 100644 --- a/xmake/modules/devel/git/clone.lua +++ b/xmake/modules/devel/git/clone.lua @@ -60,6 +60,11 @@ function main(url, opt) table.insert(argv, ifelse(type(opt.depth) == "number", tostring(opt.depth), opt.depth)) end + -- recursive? + if opt.recursive then + table.insert(argv, "--recursive") + end + -- set outputdir if opt.outputdir then table.insert(argv, path.translate(opt.outputdir)) diff --git a/xmake/modules/devel/git/ls_remote.lua b/xmake/modules/devel/git/ls_remote.lua index 391b85caf..e946a054a 100644 --- a/xmake/modules/devel/git/ls_remote.lua +++ b/xmake/modules/devel/git/ls_remote.lua @@ -50,8 +50,16 @@ function main(reftype, url) -- init reference type reftype = reftype or "refs" + -- init arguments + local argv = {"ls-remote", "--" .. reftype, url or "."} + + -- trace + if option.get("verbose") then + print("%s %s", git.program, os.args(argv)) + end + -- get refs - local data = os.iorunv(git.program, {"ls-remote", "--" .. reftype, url or "."}) + local data = os.iorunv(git.program, argv) -- get commmits and tags local refs = {} diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua index 3e0b67b30..4c274a70b 100644 --- a/xmake/modules/devel/git/pull.lua +++ b/xmake/modules/devel/git/pull.lua @@ -37,6 +37,9 @@ import("lib.detect.find_tool") -- function main(opt) + -- init options + opt = opt or {} + -- find git local git = find_tool("git") if not git then diff --git a/xmake/modules/devel/git/submodule/update.lua b/xmake/modules/devel/git/submodule/update.lua new file mode 100644 index 000000000..403bf112d --- /dev/null +++ b/xmake/modules/devel/git/submodule/update.lua @@ -0,0 +1,77 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015 - 2019, TBOOX Open Source Group. +-- +-- @author ruki +-- @file update.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- update submodule +-- +-- @param opt the argument options, e.g. repodir, init, remote, force, checkout, merge, rebase, recursive, reference, pathes +-- +-- @code +-- +-- import("devel.git.submodule") +-- +-- submodule.update("master", {repodir = "/tmp/xmake", init = true, remote = true}) +-- submodule.update("v1.0.1", {repodir = "/tmp/xmake", recursive = true, reference = "xxx", pathes = "xxx"}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find git + local git = find_tool("git") + if not git then + return + end + + -- init argv + local argv = {"submodule", "update"} + for _, name in ipairs({"init", "remote", "force", "checkout", "merge", "rebase", "recursive"}) do + if opt[name] then + table.insert(argv, "--" .. name) + end + end + if opt.reference then + table.insert(argv, "--reference") + table.insert(argv, opt.reference) + end + if opt.pathes then + table.join2(argv, opt.pathes) + end + + -- enter repository directory + local oldir = nil + if opt.repodir then + oldir = os.cd(opt.repodir) + end + + -- submodule it + os.vrunv(git.program, argv) + + -- leave repository directory + if oldir then + os.cd(oldir) + end +end |
