From 2b592ebb35851e1a7f9c95614598c07b1c056f76 Mon Sep 17 00:00:00 2001 From: Amolith Date: Sun, 18 Jan 2026 12:20:10 -0700 Subject: [PATCH] fix(path): prefix child paths with ./ Assisted-by: Claude Opus 4.5 via Amp --- dist/wt | 10 ++++++++++ spec/path_spec.lua | 6 +++--- src/wt/path.lua | 4 ++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dist/wt b/dist/wt index 93ca2d789704fb49d761b10a99afb57fcc51a311..18f5c8d89ac6c1abb7300d72d320c42d0144561e 100755 --- a/dist/wt +++ b/dist/wt @@ -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() diff --git a/spec/path_spec.lua b/spec/path_spec.lua index 768eec0783fd5504baa43a67e44fd689104b3e36..b59b2960f8fbe3ff0cd55279a69b70f8cd6ac766 100644 --- a/spec/path_spec.lua +++ b/spec/path_spec.lua @@ -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() diff --git a/src/wt/path.lua b/src/wt/path.lua index 298a46477778f8bc17bde21b6e5e6eddd55d4e98..90124d0a100179a85b42e294dac511f316aa1695 100644 --- a/src/wt/path.lua +++ b/src/wt/path.lua @@ -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