diff --git a/doc/git-worktrees.nvim.txt b/doc/git-worktrees.nvim.txt new file mode 100644 index 0000000..95eb5f3 --- /dev/null +++ b/doc/git-worktrees.nvim.txt @@ -0,0 +1,123 @@ +================================================================================ + *git-worktree.nvim* +A simple wrapper around git worktree operations, create, switch, and delete. +(There is some assumed workflow within this plugin, but pull requests are welcomed to fix that). +TOC +|options| +|Setup| +|Usage| +|Telescope| +|Create_a_worktree| +|Hooks| + + + *options* +`change_directory_command` +The vim command used to change to the new worktree directory. Set this to `tcd` +if you want to only change the `pwd` for the current vim tab. + +`update_on_change` +Updates the current buffer to point to the new work tree if the file is found in +the new project. Otherwise, the following command will be run. + +`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. + +`clearjumps_on_change` +Every time you switch branches, your jumplist will be cleared so that you don't +accidentally go backward to a different branch and edit the wrong files. +autopush: When creating a new worktree, it will push the branch to the upstream +then perform a git rebase + +`autopush` +When creating a new worktree, it will push the branch to the upstream then perform a `git rebase` + +example setup +> + require("git-worktree").setup({ + change_directory_command = -- default: "cd", + update_on_change = -- default: true, + update_on_change_command = -- default: "e .", + clearjumps_on_change = -- default: true, + autopush = -- default: false, + }) +< + + *Setup* +Repository + +This plugin does work best with a bare repo. To clone a bare repo, do the following. + +> + git clone --bare +< +If you do not use a bare repo, using telescope create command will be more helpful in the process of creating a branch. + + *Usage* +These three primary functions should cover your day-to-day. + +The path can be either relative from the git root dir or absoulut path to the worktree. +> + -- Creates a worktree. Requires the path, branch name, and the upstream + -- Example: + :lua require("git-worktree").create_worktree("feat-69", "master", "origin") + + -- switches to an existing worktree. Requires the path name + -- Example: + :lua require("git-worktree").switch_worktree("feat-69") + + -- deletes to an existing worktree. Requires the path name + -- Example: + :lua require("git-worktree").delete_worktree("feat-69") +< + + *Telescope* +Add the following to your vimrc to load the telescope extension. +> + require("telescope").load_extension("git_worktree") + Switch and Delete a worktrees + To bring up the telescope window listing your workspaces run the following + + :lua require('telescope').extensions.git_worktree.git_worktrees() + -- - switches to that worktree + -- - deletes that worktree + -- - toggles forcing of the next deletion + < + *Create_a_worktree* +To bring up the telescope window to create a new worktree run the following +> + :lua require('telescope').extensions.git_worktree.create_git_worktree() +< +First a telescope git branch window will appear. Presing enter will choose the selected branch for the branch name. If no branch is selected, then the prompt will be used as the branch name. + +After the git branch window, a prompt will be presented to enter the path name to write the worktree to. + +As of now you can not specify the upstream in the telescope create workflow, however if it finds a branch of the same name in the origin it will use it + + *Hooks* +Yes! The best part about git-worktree is that it emits information so that you can act on it. +> + local Worktree = require("git-worktree") + + -- op = Operations.Switch, Operations.Create, Operations.Delete + -- metadata = table of useful values (structure dependent on op) + -- Switch + -- path = path you switched to + -- prev_path = previous worktree path + -- Create + -- path = path where worktree created + -- branch = branch name + -- upstream = upstream remote name + -- Delete + -- path = path where worktree deleted + + Worktree.on_tree_change(function(op, metadata) + if op == Worktree.Operations.Switch then + print("Switched from " .. metadata.prev_path .. " to " .. metadata.path) + end + end) +< +This means that you can use harpoon or other plugins to perform follow up operations that will help in turbo charging your development experience! + + vim:tw=78:ts=8:ft=help:norl: