diff --git a/dist/wt b/dist/wt index 1c09a9c7c89255ae26f2bcfcbc16b83399e2884b..3fe33e4ee362adde90e03e3141c17597a631032d 100755 --- a/dist/wt +++ b/dist/wt @@ -861,6 +861,36 @@ end return M ]] +_EMBEDDED_MODULES["wt.cmd.fetch"] = [[-- SPDX-FileCopyrightText: Amolith +-- +-- SPDX-License-Identifier: GPL-3.0-or-later + +local exit = require("wt.exit") +local shell = require("wt.shell") +local git = require("wt.git") + +---@class wt.cmd.fetch +local M = {} + +---Fetch all remotes with pruning +function M.cmd_fetch() + local root, err = git.find_project_root() + if not root then + shell.die(err --[[@as string]]) + return + end + + local git_dir = root .. "/.bare" + local output, code = shell.run_cmd("GIT_DIR=" .. git_dir .. " git fetch --all --prune") + io.write(output) + if code ~= 0 then + os.exit(exit.EXIT_SYSTEM_ERROR) + end +end + +return M +]] + if _VERSION < "Lua 5.2" then io.stderr:write("error: wt requires Lua 5.2 or later\n") @@ -912,6 +942,9 @@ local help_mod = require("wt.help") local print_usage = help_mod.print_usage local show_command_help = help_mod.show_command_help +local fetch_mod = require("wt.cmd.fetch") +local cmd_fetch = fetch_mod.cmd_fetch + ---@param args string[] local function cmd_clone(args) -- Parse arguments: [--remote name]... [--own] @@ -1640,21 +1673,6 @@ local function cmd_list() table_handle:close() end -local function cmd_fetch() - local root, err = find_project_root() - if not root then - die(err --[[@as string]]) - return - end - - local git_dir = root .. "/.bare" - local output, code = run_cmd("GIT_DIR=" .. git_dir .. " git fetch --all --prune") - io.write(output) - if code ~= 0 then - os.exit(EXIT_SYSTEM_ERROR) - end -end - ---List directory entries (excluding . and ..) ---@param path string ---@return string[] diff --git a/src/main.lua b/src/main.lua index 0da5252b8c1aca0f00725e459be92424432cee87..9ee4770b3086b3cdb173ee446b2bc5c872df7382 100644 --- a/src/main.lua +++ b/src/main.lua @@ -54,6 +54,9 @@ local help_mod = require("wt.help") local print_usage = help_mod.print_usage local show_command_help = help_mod.show_command_help +local fetch_mod = require("wt.cmd.fetch") +local cmd_fetch = fetch_mod.cmd_fetch + ---@param args string[] local function cmd_clone(args) -- Parse arguments: [--remote name]... [--own] @@ -782,21 +785,6 @@ local function cmd_list() table_handle:close() end -local function cmd_fetch() - local root, err = find_project_root() - if not root then - die(err --[[@as string]]) - return - end - - local git_dir = root .. "/.bare" - local output, code = run_cmd("GIT_DIR=" .. git_dir .. " git fetch --all --prune") - io.write(output) - if code ~= 0 then - os.exit(EXIT_SYSTEM_ERROR) - end -end - ---List directory entries (excluding . and ..) ---@param path string ---@return string[] diff --git a/src/wt/cmd/fetch.lua b/src/wt/cmd/fetch.lua new file mode 100644 index 0000000000000000000000000000000000000000..31e7f6b82915ab7e5c31e05fef88db4872376dd4 --- /dev/null +++ b/src/wt/cmd/fetch.lua @@ -0,0 +1,28 @@ +-- SPDX-FileCopyrightText: Amolith +-- +-- SPDX-License-Identifier: GPL-3.0-or-later + +local exit = require("wt.exit") +local shell = require("wt.shell") +local git = require("wt.git") + +---@class wt.cmd.fetch +local M = {} + +---Fetch all remotes with pruning +function M.cmd_fetch() + local root, err = git.find_project_root() + if not root then + shell.die(err --[[@as string]]) + return + end + + local git_dir = root .. "/.bare" + local output, code = shell.run_cmd("GIT_DIR=" .. git_dir .. " git fetch --all --prune") + io.write(output) + if code ~= 0 then + os.exit(exit.EXIT_SYSTEM_ERROR) + end +end + +return M