diff options
| author | ruki <[email protected]> | 2022-04-12 23:05:38 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-04-12 23:05:38 +0800 |
| commit | 8db3cdabf865392bdf3734a3cc0803bdbd045a09 (patch) | |
| tree | 741e115fffb231781ec8d66b9be3f68b69086a53 | |
| parent | 52f324b543b512f53a75a653f3b32cc7dbfe601e (diff) | |
reset files
| -rw-r--r-- | xmake/modules/devel/git/branch.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/private/service/remote_build/session.lua | 14 |
2 files changed, 64 insertions, 2 deletions
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 diff --git a/xmake/modules/private/service/remote_build/session.lua b/xmake/modules/private/service/remote_build/session.lua index 7d961faaa..2adf73dfa 100644 --- a/xmake/modules/private/service/remote_build/session.lua +++ b/xmake/modules/private/service/remote_build/session.lua @@ -76,6 +76,7 @@ end -- reset sourcedir function session:_reset_sourcedir() + vprint("%s: reset %s", self, self:sourcedir()) -- init sourcedir first if .git not exists local sourcedir = self:sourcedir() @@ -86,8 +87,17 @@ function session:_reset_sourcedir() git.init({repodir = sourcedir}) end - -- checkout and reset branch - -- TODO + -- reset the current branch + local branch = git.branch({repodir = sourcedir}) + if branch then + git.clean({repodir = sourcedir, force = true, all = true}) + git.reset({repodir = sourcedir, hard = true}) + end +end + +-- get working branch of the source directory +function session:_source_branch() + return "remote_build" end function session:__tostring() |
