forked from ThePrimeagen/git-worktree.nvim
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2eafc1d
commit 1843a77
Showing
3 changed files
with
42 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,23 @@ | ||
local M = {} | ||
|
||
---@class GitWorktreeConfig | ||
---@class GitWorktree.Config | ||
local defaults = { | ||
change_directory_command = 'cd', | ||
update_on_change = true, | ||
update_on_change_command = 'e .', | ||
clearjumps_on_change = true, | ||
confirm_telescope_deletions = true, | ||
autopush = false, | ||
} | ||
|
||
---@class GitWorktreePartialConfig | ||
---@field change_directory_command? string | ||
---@field update_on_change? boolean | ||
---@field update_on_change_command? string | ||
---@field clearjumps_on_change? boolean | ||
---@field confirm_telescope_deletions? boolean | ||
---@field autopush? boolean | ||
---@type GitWorktree.Config | ||
M.options = {} | ||
|
||
---@return GitWorktreeConfig | ||
function M.get_default_config() | ||
return { | ||
change_directory_command = 'cd', | ||
update_on_change = true, | ||
update_on_change_command = 'e .', | ||
clearjumps_on_change = true, | ||
confirm_telescope_deletions = true, | ||
autopush = false, | ||
} | ||
---@param opts? GitWorktree.Config | ||
function M.setup(opts) | ||
M.options = vim.tbl_deep_extend('force', defaults, opts or {}) | ||
end | ||
|
||
---@param partial_config GitWorktreePartialConfig | ||
---@param latest_config GitWorktreeConfig? | ||
---@return GitWorktreeConfig | ||
function M.merge_config(partial_config, latest_config) | ||
local config = latest_config or M.get_default_config() | ||
|
||
config = vim.tbl_extend('force', config, partial_config) | ||
|
||
return config | ||
end | ||
M.setup() | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
local stub = require('luassert.stub') | ||
|
||
describe('config', function() | ||
local notify_once = stub(vim, 'notify_once') | ||
local notify = stub(vim, 'notify') | ||
|
||
it('returns the default config', function() | ||
local Config = require('git-worktree.config') | ||
assert.truthy(Config.options.change_directory_command) | ||
end) | ||
|
||
it('can have configuration applied', function() | ||
local Config = require('git-worktree.config') | ||
Config.setup { change_directory_command = 'test' } | ||
assert.equals(Config.options.change_directory_command, 'test') | ||
end) | ||
|
||
it('No notifications at startup.', function() | ||
assert.stub(notify_once).was_not_called() | ||
assert.stub(notify).was_not_called() | ||
end) | ||
end) |