diff options
| author | ruki <[email protected]> | 2017-05-18 13:53:59 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-05-18 13:54:10 +0800 |
| commit | 3b5f654b578fd63ae4ed40599b150337f633074e (patch) | |
| tree | 638711704b051fdddfadf15d31802fdaf1d22d1f /xmake/modules/devel/git/clone.lua | |
| parent | c1165f853e205bbd5bd1395dd4f4a6b725facc8e (diff) | |
add git.clone and http.download module
Diffstat (limited to 'xmake/modules/devel/git/clone.lua')
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua new file mode 100644 index 000000000..c717065b8 --- /dev/null +++ b/xmake/modules/devel/git/clone.lua @@ -0,0 +1,74 @@ +--!The Make-like Build Utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file clone.lua +-- + +-- imports +import("core.base.option") +import("detect.tool.find_git") + +-- clone url +-- +-- @param url the git url +-- @param opt the argument options +-- +-- @code +-- +-- import("devel.git") +-- +-- git.clone("[email protected]:tboox/xmake.git") +-- git.clone("[email protected]:tboox/xmake.git", {depth = 1, branch = "master", outputdir = "/tmp/xmake"}) +-- +-- @endcode +-- +function main(url, opt) + + -- find git + local program = find_git() + if not program then + return + end + + -- init argv + local argv = {"clone", url} + + -- set branch + opt = opt or {} + if opt.branch then + table.insert(argv, "-b") + table.insert(argv, opt.branch) + end + + -- set depth + if opt.depth then + table.insert(argv, "--depth") + table.insert(argv, ifelse(type(opt.depth) == "number", tostring(opt.depth), opt.depth)) + end + + -- set outputdir + if opt.outputdir then + table.insert(argv, path.translate(opt.outputdir)) + end + + -- clone it + os.vrunv(program, argv) +end |
