Skip to content

Commit

Permalink
fix: don't create empty extra command files
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronr committed Aug 27, 2024
1 parent f8ccc1b commit 337ac10
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lua/auto-session/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ end
---@private
---Get the hook commands from the config and run them
---@param hook_name string
---@return table Results of the commands
---@return table|nil Results of the commands
function AutoSession.run_cmds(hook_name)
local cmds = Config[hook_name .. "_cmds"]
return Lib.run_hook_cmds(cmds, hook_name)
Expand Down
6 changes: 3 additions & 3 deletions lua/auto-session/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,13 @@ end

---@param cmds table Cmds to run
---@param hook_name string Name of the hook being run
---@return table Results of the cmds
---@return table|nil Results of the cmds
function Lib.run_hook_cmds(cmds, hook_name)
local results = {}
if Lib.is_empty_table(cmds) then
return results
return nil
end

local results = {}
for _, cmd in ipairs(cmds) do
Lib.logger.debug(string.format("Running %s command: %s", hook_name, cmd))
local success, result
Expand Down
4 changes: 4 additions & 0 deletions tests/cmds_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe("The default config", function()
-- Make sure the session has our buffer
TL.assertSessionHasFile(TL.default_session_path, TL.test_file)
assert.True(as.session_exists_for_cwd())

-- Make sure there isn't an extra commands file by default
local default_extra_cmds_path = TL.default_session_path:gsub("%.vim$", "x.vim")
assert.equals(0, vim.fn.filereadable(default_extra_cmds_path))
end)

it("can restore a session for the cwd", function()
Expand Down

0 comments on commit 337ac10

Please sign in to comment.