@@ -163,6 +163,10 @@ function M.relative_path(from, to)
return "./"
end
+ if up_count == 0 then
+ return "./" .. table.concat(result, "/")
+ end
+
return table.concat(result, "/")
end
@@ -971,6 +975,7 @@ function M.cmd_clone(args)
local positional = {}
while i <= #args do
local a = args[i]
+ ---@cast a string
if a == "--remote" then
if not args[i + 1] then
shell.die("--remote requires a name")
@@ -994,6 +999,7 @@ function M.cmd_clone(args)
shell.die("unexpected argument: " .. positional[2])
end
url = positional[1]
+ ---@cast url string
-- Extract project name from URL
local project_name = config.extract_project_name(url)
@@ -1264,6 +1270,7 @@ function M.cmd_new(args)
local positional = {}
while i <= #args do
local a = args[i]
+ ---@cast a string
if a == "--remote" then
if not args[i + 1] then
shell.die("--remote requires a name")
@@ -1285,6 +1292,7 @@ function M.cmd_new(args)
shell.die("unexpected argument: " .. positional[2])
end
project_name = positional[1]
+ ---@cast project_name string
-- Check if project directory already exists
local cwd = shell.get_cwd()
@@ -1480,6 +1488,7 @@ function M.cmd_add(args)
else
shell.die("unexpected argument: " .. positional[3])
end
+ ---@cast branch string
local root, err = git.find_project_root()
if not root then
@@ -1510,6 +1519,7 @@ function M.cmd_add(args)
.. existing_wt.path
.. "\nhint: run `git worktree prune` to clean up stale entries"
)
+ return
end
wt_check:close()
@@ -166,12 +166,12 @@ describe("relative_path", function()
describe("parent/child relationships", function()
it("computes path to child", function()
local rel = wt.relative_path("/a", "/a/b")
- assert.are.equal("b", rel)
+ assert.are.equal("./b", rel)
end)
it("computes path to deeply nested child", function()
local rel = wt.relative_path("/a", "/a/b/c/d")
- assert.are.equal("b/c/d", rel)
+ assert.are.equal("./b/c/d", rel)
end)
it("computes path to parent", function()
@@ -197,7 +197,7 @@ describe("relative_path", function()
describe("root paths", function()
it("handles from root to child", function()
local rel = wt.relative_path("/", "/a/b")
- assert.are.equal("a/b", rel)
+ assert.are.equal("./a/b", rel)
end)
it("handles from child to root", function()
@@ -52,6 +52,10 @@ function M.relative_path(from, to)
return "./"
end
+ if up_count == 0 then
+ return "./" .. table.concat(result, "/")
+ end
+
return table.concat(result, "/")
end