diff options
| author | ruki <[email protected]> | 2021-08-29 21:56:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-08-29 21:56:52 +0800 |
| commit | ab2c5e2a3b29bb63b23a7fa59c3f6d56cc56c47c (patch) | |
| tree | 0d2324fcf8b215228a0c1ce49baed48b61b792cf | |
| parent | 4497dd33fb475a388d5d51192d432b0156be78a3 (diff) | |
improve git ops
| -rw-r--r-- | xmake/modules/devel/git/apply.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/devel/git/checkout.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/devel/git/clean.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/devel/git/lastcommit.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 15 | ||||
| -rw-r--r-- | xmake/modules/devel/git/reset.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/devel/git/submodule/update.lua | 21 |
7 files changed, 12 insertions, 89 deletions
diff --git a/xmake/modules/devel/git/apply.lua b/xmake/modules/devel/git/apply.lua index 97923da02..ccfd5bf80 100644 --- a/xmake/modules/devel/git/apply.lua +++ b/xmake/modules/devel/git/apply.lua @@ -44,17 +44,6 @@ function main(patchfile, opt) opt = opt or {} local argv = {"apply", "--reject", "--ignore-whitespace", patchfile} - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- apply it - os.vrunv(git.program, argv) - - -- leave repository directory - if oldir then - os.cd(oldir) - end + os.vrunv(git.program, argv, {curdir = opt.repodir}) end diff --git a/xmake/modules/devel/git/checkout.lua b/xmake/modules/devel/git/checkout.lua index 7a32aa3b1..c78d8f439 100644 --- a/xmake/modules/devel/git/checkout.lua +++ b/xmake/modules/devel/git/checkout.lua @@ -47,17 +47,6 @@ function main(commit, opt) -- init argv local argv = {"checkout", commit} - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- checkout it - os.vrunv(git.program, argv) - - -- leave repository directory - if oldir then - os.cd(oldir) - end + os.vrunv(git.program, argv, {curdir = opt.repodir}) end diff --git a/xmake/modules/devel/git/clean.lua b/xmake/modules/devel/git/clean.lua index ae21c3d88..52fa81a0b 100644 --- a/xmake/modules/devel/git/clean.lua +++ b/xmake/modules/devel/git/clean.lua @@ -61,17 +61,6 @@ function main(opt) table.insert(argv, "-x") end - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- clean it - os.vrunv(git.program, argv) - - -- leave repository directory - if oldir then - os.cd(oldir) - end + os.vrunv(git.program, argv, {curdir = opt.repodir}) end diff --git a/xmake/modules/devel/git/lastcommit.lua b/xmake/modules/devel/git/lastcommit.lua index 876812f86..1ad6de1f4 100644 --- a/xmake/modules/devel/git/lastcommit.lua +++ b/xmake/modules/devel/git/lastcommit.lua @@ -57,21 +57,10 @@ function main(opt) envs = {ALL_PROXY = proxy_conf} end - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- get last commit - local lastcommit = os.iorunv(git.program, argv, {envs = envs}) + local lastcommit = os.iorunv(git.program, argv, {envs = envs, curdir = opt.repodir}) if lastcommit then lastcommit = lastcommit:trim() end - - -- leave repository directory - if oldir then - os.cd(oldir) - end return lastcommit end diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua index 9970f8dbc..412e6e757 100644 --- a/xmake/modules/devel/git/pull.lua +++ b/xmake/modules/devel/git/pull.lua @@ -58,18 +58,12 @@ function main(opt) table.insert(argv, "--tags") end - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- use proxy? local envs local proxy_conf = proxy.config() if proxy_conf then -- get proxy configuration from the current remote url - local remoteinfo = try { function() return os.iorunv(git.program, {"remote", "-v"}) end } + local remoteinfo = try { function() return os.iorunv(git.program, {"remote", "-v"}, {curdir = opt.repodir}) end } if remoteinfo then for _, line in ipairs(remoteinfo:split('\n', {plain = true})) do local splitinfo = line:split("%s+") @@ -86,10 +80,5 @@ function main(opt) end -- pull it - os.vrunv(git.program, argv, {envs = envs}) - - -- leave repository directory - if oldir then - os.cd(oldir) - end + os.vrunv(git.program, argv, {envs = envs, curdir = opt.repodir}) end diff --git a/xmake/modules/devel/git/reset.lua b/xmake/modules/devel/git/reset.lua index 28b984008..4ed798d25 100644 --- a/xmake/modules/devel/git/reset.lua +++ b/xmake/modules/devel/git/reset.lua @@ -71,17 +71,6 @@ function main(opt) table.insert(argv, opt.commit) end - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- reset it - os.vrunv(git.program, argv) - - -- leave repository directory - if oldir then - os.cd(oldir) - end + os.vrunv(git.program, argv, {curdir = opt.repodir}) end diff --git a/xmake/modules/devel/git/submodule/update.lua b/xmake/modules/devel/git/submodule/update.lua index 5d9323a02..881663706 100644 --- a/xmake/modules/devel/git/submodule/update.lua +++ b/xmake/modules/devel/git/submodule/update.lua @@ -58,37 +58,26 @@ function main(opt) table.join2(argv, opt.paths) end - -- enter repository directory - local oldir = nil - if opt.repodir then - oldir = os.cd(opt.repodir) - end - -- enable long paths local longpaths_old local longpaths_changed = false if opt.longpaths then - local longpaths_old = try {function () return os.iorunv(git.program, {"config", "--get", "--global", "core.longpaths"}) end} + local longpaths_old = try {function () return os.iorunv(git.program, {"config", "--get", "--global", "core.longpaths"}, {curdir = opt.repodir}) end} if not longpaths_old or not longpaths_old:find("true") then - os.vrunv(git.program, {"config", "--global", "core.longpaths", "true"}) + os.vrunv(git.program, {"config", "--global", "core.longpaths", "true"}, {curdir = opt.repodir}) longpaths_changed = true end end -- submodule it - os.vrunv(git.program, argv) + os.vrunv(git.program, argv, {curdir = opt.repodir}) -- restore old long paths configuration if longpaths_changed then if longpaths_old and longpaths_old:find("false") then - os.vrunv(git.program, {"config", "--global", "core.longpaths", "false"}) + os.vrunv(git.program, {"config", "--global", "core.longpaths", "false"}, {curdir = opt.repodir}) else - os.vrunv(git.program, {"config", "--global", "--unset", "core.longpaths"}) + os.vrunv(git.program, {"config", "--global", "--unset", "core.longpaths", {curdir = opt.repodir}}) end end - - -- leave repository directory - if oldir then - os.cd(oldir) - end end |
