From 8db3cdabf865392bdf3734a3cc0803bdbd045a09 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 12 Apr 2022 23:05:38 +0800 Subject: reset files --- xmake/modules/devel/git/branch.lua | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 xmake/modules/devel/git/branch.lua (limited to 'xmake/modules/devel/git') diff --git a/xmake/modules/devel/git/branch.lua b/xmake/modules/devel/git/branch.lua new file mode 100644 index 000000000..391ffd27e --- /dev/null +++ b/xmake/modules/devel/git/branch.lua @@ -0,0 +1,52 @@ +--!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-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file branch.lua +-- + +-- imports +import("core.base.option") +import("lib.detect.find_tool") + +-- get current branch +-- +-- @param opt the argument options +-- +-- @code +-- +-- import("devel.git") +-- +-- local branch = git.branch() +-- local branch = git.branch({repodir = "/tmp/xmake"}) +-- +-- @endcode +-- +function main(opt) + opt = opt or {} + local git = assert(find_tool("git"), "git not found!") + local argv = {"branch"} + if not option.get("verbose") then + table.insert(argv, "-q") + end + local branch = os.iorunv(git.program, argv, {curdir = opt.repodir}) + if branch then + branch = branch:trim() + if #branch > 0 then + return branch + end + end +end -- cgit v1.3.1