Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update_on_worktree_change config option, and depreacte update_on_change_command #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

KirkEasterson
Copy link

@KirkEasterson KirkEasterson commented Aug 27, 2022

This pull request allows for more control over what happens when the current working directory is changed to the specified worktree. A workaround was mentioned in #13 , but it isn't ideal since git-worktree would always run the code to open the current buffer in the specified worktree. With the changes in this PR, the workaround can be achieved without running unnecessary code.

No breaking changes are introduced, and users won't experience any different behavior with their current configs. But the assumption was made that this would lead to the eventual deprecation of on_change_command. This can be discussed, because I don't feel strongly about it.

I use auto-session for managing sessions, but any session-manager/code can be used here. A sample configuration is below.

local worktree = require("git-worktree")

local update_on_worktree_change = function(op, metadata)
	vim.api.nvim_command("RestoreSession")
end

require("git-worktree").setup({
	clear_jumps_on_change = false, -- this is handled by auto-session
	update_on_worktree_change = update_on_worktree_change,
})

previous option of `update_on_change` a default value of `nil`. This
allows the user to continue using their previous config, but a
deprecation warning is shown when setting `update_on_change`
`update_on_change_command`: The vim command to run during the `update_on_change` event.
Note, that this command will only be run when the current file is not found in the new worktree.
This option defaults to `e .` which opens the root directory of the new worktree.
`update_on_new_worktree`: The lua function to be run after changing the working
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now realize that update_on_worktree_change may be more appropriate. I will update the PR.

@KirkEasterson KirkEasterson changed the title Add update_on_new_worktree config option, and depreacte update_on_change_command Add update_on_worktree_tree config option, and depreacte update_on_change_command Aug 27, 2022
@KirkEasterson KirkEasterson changed the title Add update_on_worktree_tree config option, and depreacte update_on_change_command Add update_on_worktree_change config option, and depreacte update_on_change_command Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant