Skip to content

Commit 95d7047

Browse files
fix(refile): Remove leading slash when refiling to destination
1 parent 55b68bb commit 95d7047

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

lua/orgmode/utils/fs.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ function M.trim_common_root(paths)
7575
local common_root = get_common_root()
7676

7777
if #common_root == 0 then
78-
return paths
78+
return vim.tbl_map(function(path)
79+
return path:gsub('^/', '')
80+
end, paths)
7981
end
8082

81-
local root = table.concat(common_root, '/') .. '/'
83+
local root = '/' .. table.concat(common_root, '/') .. '/'
8284
local result = {}
8385
for _, path in ipairs(paths) do
8486
local relative_path = path:sub(#root + 1)

tests/plenary/utils/fs_spec.lua

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ end)
9090
describe('trim_common_root', function()
9191
it('trims the common root when all files share the same root with the shortest one', function()
9292
local result = fs_utils.trim_common_root({
93-
'foo/bar/baz.org',
94-
'foo/bar/baz/bar.org',
95-
'foo/bar/baz3.org',
93+
'/foo/bar/baz.org',
94+
'/foo/bar/baz/bar.org',
95+
'/foo/bar/baz3.org',
9696
})
9797
assert.are.same({
9898
'baz.org',
@@ -103,11 +103,11 @@ describe('trim_common_root', function()
103103

104104
it('trims the common root when there are multiple different roots', function()
105105
local result = fs_utils.trim_common_root({
106-
'foo/bar/tea/notes.org',
107-
'foo/bar/tea/todos.org',
108-
'foo/bar/baz/work.org',
109-
'foo/bar/baz/personal.org',
110-
'foo/bar/baz/project.org',
106+
'/foo/bar/tea/notes.org',
107+
'/foo/bar/tea/todos.org',
108+
'/foo/bar/baz/work.org',
109+
'/foo/bar/baz/personal.org',
110+
'/foo/bar/baz/project.org',
111111
})
112112

113113
assert.are.same({
@@ -121,11 +121,11 @@ describe('trim_common_root', function()
121121

122122
it('returns paths as they are if they do not share the common root', function()
123123
local result = fs_utils.trim_common_root({
124-
'foo/bar/tea/notes.org',
125-
'foo/bar/tea/todos.org',
126-
'foo/bar/baz/work.org',
127-
'foo/bar/baz/personal.org',
128-
'other/bar/baz/project.org',
124+
'/foo/bar/tea/notes.org',
125+
'/foo/bar/tea/todos.org',
126+
'/foo/bar/baz/work.org',
127+
'/foo/bar/baz/personal.org',
128+
'/other/bar/baz/project.org',
129129
})
130130

131131
assert.are.same({

0 commit comments

Comments
 (0)