Giter Club home page Giter Club logo

git-worktree.nvim's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-worktree.nvim's Issues

[Configuration] Make ":Ex path" configurable

It would be great if the user could configure the command which gets executed upon update_on_change.
Personally, I used to have netrw disabled and instead use vim-dirvish. This would be an easy fix if one could specify a setup-option (say e.g. update_on_change_command) and a user could exchange :Ex with :Dirvish. However, once we make this configurable one could even allow any vim-command (or even any lua function) to be given here. Right now, I am thinking that something like :Telescope git_files might be even cooler ๐Ÿค”

I am happy to open a PR for this but wanted to get some input first.

  • would a simple string command-option be enough?
  • or do you think we need a lua function as the configurable option, such that we can also handle path being passed into it?
  • actually on second though, why do we need to pass path to it? Isn't simply :Ex enough?

does not handle branch name with "/"

the plugin as currently written uses the folder name that needs to match the branch name but I have branch names with "/". when I create a worktree everything after the "/" gets cut off

Fails to find correct git_worktree_root

I open vim in my home directory, then change the directory to that of a git worktree within a bare repository. Then I try to switch to a different worktree, but git-worktree falls back to the :Explore command because it can't find the file - after adding some debugging print statements in init.lua I find that it is trying to find it inside my home directory, because local git_worktree_root = vim.loop.cwd() is called when the plugin is loaded.

errors during set_branch

not sure if I am doing something wrong or misunderstanding something

steps I am doing

  1. git clone --bare
  2. cd <repo.git>
  3. nvim
  4. :lua require('git-worktree').create_worktree("master", "origin/master")

it creates the worktree but I get an error on set_branch saying the requested upstream branch "origin/master" does not exist

thoughts on what is happening?

Feature request: copy file into other worktree

Sometimes I make changes to a script, and then find upon running it that I was editing the one in a different worktree. To resolve that, I need to:

:sav %[tab]

and then move back using arrowkeys to where the worktree part of the directory is, change it to the worktree that I intended to edit in the first place, and press enter. This is tedious, so I would like a way to do this in git-worktree.

To add to this frustration, sometimes I did actually have the correct version of that file already opened in some other hidden buffer. So then :sav gives me this error:

E139: File is loaded in another buffer

For which Ingo gives the workaround here - although I would just always do the exception-handler code and not bother with w/sav at all:

try
   exe r 'w>>' . ' !'[a:overwrite] . fnameescape(a:fname)
catch /^Vim\%((\a\+)\)\=:E139/
    exe r 'yank'
    exe 'sbuffer' fnameescape(a:fname)
    $put
    hide
endtry

So, the function should yank the buffer contents, open the desired file - after the user fuzzy-selects the desired worktree of course - and then replace that file's contents with the yanked contents.

folder structure: cant find dir in cdpath

Just started to use git-worktree so noob here.

If my folder structure is the following:

project/
    |__ master
             |__.git/
             |__code.py
    |__ test
            |__code.py

and for example, I am in the test worktree and I call switch to master, it fails because it looks for project/test/master whereas I want to look for project/master.

Is this possible?

BUG? - `:bnext` and `:bprevious` takes you to file on previous worktree

How to reproduce:

  1. Open project
  2. Switch to an existing worktree A
  3. Open SomeFile and move cursor 10j or make some edit and save
  4. Switch to an existing worktree B where SomeFile also exists
  5. Notice that the cursor position correctly resets
  6. Do :bn followed by :bp
  7. Notice that you're back to SomeFile on worktree A

When is force deletion necessary?

Sorry for asking here, but I'm brand new to git work trees. I can't find this answer on the great Googles or DDGs...

When is a force deletion necessary? Is it the same rules as usual? If there are commits locally that are not pushed upstream, force deletion is necessary?

Thanks!

Make it possible to select branch to base the new worktree and branch on [feature request]

I'm not sure if this can already be done somehow, but did not find any information on this.

I have a situation where I would like to make a new worktree and branch based on some other branch. Currently creating new worktree bases it on master/default branch if I'm not mistaken.

Creating new worktree based on other branch can be done in command line with git worktree add -b "name" "path" "branch to base on" where branch to base on could be for example origin/develop. But I would like to see this implemented to the telescope extension.

Make Automatically Pushing an Option

I personally would prefer that when creating a worktree the plugin does not automatically push to origin. A possible solution would be something like this when calling setup:

require('git-worktree').setup({
    autopush = false,
})

Could not change to directory: /Users/client/OneDrive

looks like the issue is caused by my path folder includes space (folder name is OneDrive - Work). Unfortunately changing the folder name is not an option. Wondering do we already have a workaround in the extension?

Error executing vim.schedule lua callback: ...cker/start/git-worktree.nvim/lua/git-worktree/status.lua:63: 1 / 2: Could not chang to directory: /Users/client/OneDrive
stack traceback:
        [C]: in function 'error'
        ...cker/start/git-worktree.nvim/lua/git-worktree/status.lua:63: in function 'error'
        ...packer/start/git-worktree.nvim/lua/git-worktree/init.lua:160: in function 'change_dirs'
        ...packer/start/git-worktree.nvim/lua/git-worktree/init.lua:419: in function <...packer/start/git-worktree.nvim/lua/git-worktree/init.lua:418>

Feature: find bare root when creating worktrees

๐Ÿ‘‹,

I'm using this plugin together with git clone --bare <repo> .git, which also in recommended in the README. When triggering Telescope git_worktree create_git_worktree it asks for a path to create the worktree in. If I input test as a path it will add the worktree in .git/test which I obviously do not want. The correct placement would be ../test here.

It would be really nice if was possible to configure git-worktree.nvim so it's able to find the bare root.

Open worktree in a new tab and retain the working directory of the old tab

My current config:

require("git-worktree").setup {
  change_directory_command = "tcd",
  update_on_change_command = "tabnew",
}

If I create a new worktree, it opens it in a new tab and correctly sets the working directory to the path of the new worktree. However the previous tab where I ran the command also changes its directory to the new worktree.

I would like the previous tab to maintain the working directory rather than switch to the new worktree. I attempted to use a hook to set the working directory in the new tab only, but was unsuccessful.

Discussion: Using branch name vs path in switch/delete api

@ThePrimeagen Continuing the discussion from #29 since it was not resolved

I chose path since it matches how the git cli works. but I do see benefits to using the branch name since it is more likely to be shorter name than the path. On the other side, if you use the telescope plugin you can fuzzy over either in the current master.

Close if you are fine with the current implementation or we can look into changing it

Error using telescope command

This definitely could be a configuration issue or just me being a batler, however when I use the telescope command

:lua require("telescope").extensions.git_worktree.git_worktrees(),

I get the following error after selecting a worktree:

Error executing luv callback:                                                     
...load/plugged/git-worktree.nvim/lua/git-worktree/init.lua:219: worktree does not exists, please create it first

Note: worktrees are created (as far as I know)

here is the result from ls command at root dir:

HEAD                  description           packed-refs
S2-dev                hooks                 refs
U15_Product_Catalogue info                  worktrees
config                objects

Out of date README due to non bare repo commit

There are lots of new support within git worktree thanks for Polar, and we don't have it documented yet! Please show how to do the creation via telescope and document anything else that is needed to be known, especially around the apis.

Feature request; option to skip git fetch

It would be great to have a global flag I can add to my vimrc to skip fetching when doing create_worktree. In the repo's I work in, it takes a long time to fetch (there are new commits every few minutes), and it's just not necessary for every work tree added.

Confirm deletions in telescope

I'd like to have to confirm deletions in telescope so I can have a chance to rethink if I am deleting the wrong worktree. Is there an easy way to achieve that built in?

Changing worktree while having active LSP Clients

So i think i stumbled upon an issue. The scenario is the following

  1. Open a file (readme.md for example) from the master worktree
  2. Have lsp clients auto attach and initialize (i.e the lsp root dir points at the master worktree dir)
  3. Create another worktree and/orChange worktree (pre existing) to another one also having the same readme file
  4. Git-worktree will understand the file already exists and execute the update on change, i assume (which is just e .).
  5. The pwd will change but the lsp client remains attached and still points at the master worktree as root directory

So what options do we have here, this is reproducible for any type of file not just markdown, i gave it as an obvious example since it is easy to test with (pretty much all work trees will no doubt have that file existing). Another important points is that if you have a lot of files and by proxy buffers open from the old worktree and you switch, only the current might get refreshed to the one in the changed worktree, but the rest will still point to the old one, maybe that is somewhat of a useful usecase for others, but i see worktrees as somewhat independent and isolated and in that case the most straight forward solution is to just delete all buffers (related to the old worktree using prev_path).
As a workaround, could I just kill all buffers with the callback command that already exists as a settable property ?

Add additional "pre" hooks

I'm using the hooks to handle docker-composing up / down containers as I create or switch between worktrees. The only issue I have is that there's no pre-delete hook that would allow me to run docker-compose down. I imagine this would be useful for other things as well to clean up resources when a worktree is removed.

My proposal would be to add an additional Deleting hook that receives the path of the to be deleted worktree.

Feature: optionally use `:tcd` rather than `:cd`

I think it would be great to be able to specify whether :cd or :tcd should be used. To give a concrete example:

Consider I am working on a feature of a specific project.
An issue gets raised and I want to work on a quick fix for it.
Rather than loosing my nice vim session, I want to quickly switch to a new worktree.
I have several options:

  1. a new tmux session (but I am already in the right project, so why would I need to do that?)
  2. a new tmux tab (but I want to keep those as opening in my home folder and not the current dir)
  3. a new vim tab (pefect, because I am already where I want to be ๐Ÿ‘)

But now, when switching worktrees in the new vim tab, the :cd will affect the entire vim instance. If I can configure this plugin to use :tcd instead, this problem would be solved ๐ŸŽ‰

I can look into implementing this later this or next week. Just wanted to get the idea out here and see what the reaction is before starting on it ๐Ÿ‘

fzf-lua support

This is more of a notification than an issue. Here is how I integrated fzf-lua with git-worktree.nvim instead of telescope. Note that the below code force-deletes with <c-f> but always asks for confirmation first.

local parse_entry = function(entry)
    local parsed = vim.split(entry, '%s+')
    return { path = parsed[1], hash = parsed[2], branch = parsed[3]:sub(2, #parsed[3] - 1) }
end

local switch_worktree = function(selected, _)
    local parsed = parse_entry(selected[1])

    require('git-worktree').switch_worktree(parsed.branch)
end

local delete_worktree = function(selected, _)
    local parsed = parse_entry(selected[1])
    vim.ui.input({
        prompt = string.format('Delete worktree %s? [y/N] ', parsed.branch),
    }, function(input)
        if vim.trim(input):lower() == 'y' then
            require('git-worktree').delete_worktree(parsed.branch, true)
        end
    end)
end

local fzf = require 'fzf-lua'
local actions = require 'fzf-lua.actions'

local create_worktree = function(_)
    local query = fzf.config.__resume_data.last_query
    if query == nil or query == '' then
        return
    end

    local path, branch, upstream = unpack(vim.split(vim.trim(query), ' '))
    branch = not branch and vim.fn.fnamemodify(path, ':t') or branch

    require('git-worktree').create_worktree(path, branch, upstream)
end

-- call with require('file').git_worktrees()
return {
    git_worktrees = function()
        local opts = fzf.config.normalize_opts({}, fzf.config.globals.git)

        opts.cmd = fzf.path.git_cwd('git worktree list | sed "s|$HOME|~|g"', opts)

        opts.actions = {
            ['default'] = switch_worktree,
            ['ctrl-a'] = { create_worktree, actions.resume },
            ['ctrl-d'] = { delete_worktree, actions.resume },
        }

        fzf.core.fzf_wrap(opts, opts.cmd, function(selected)
            if not selected then
                return
            end
            actions.act(opts.actions, selected, opts)
        end)()
    end,
}

Can't use "/" inside of the name of the branch

If I use a "/" inside of the name of the branch. Let's say I want to create or add a "fix/something" it will create a first folder named "fix" and inside of this folder a second one named "something" and the branch will be named "something" not "fix/something"

Copy over git ignored files between worktrees

I am trying to symlink (should be the same as copying) my git ignored secrets and .env. I got it working for the 1st worktree created but subsequent worktree symlinks are messed up as current dir is not root anymore

local worktree = require("git-worktree")

worktree.on_tree_change(function(op, metadata)
	if op == worktree.Operations.Create then
		local worktree_path = vim.fn.getcwd() .. "/" .. metadata.path
		local secrets_path = "~/secrets"
		local copy_all_cmd = "ln -s " .. secrets_path .. "/* " .. worktree_path
		local copy_hidden_cmd = "ln -s " .. secrets_path .. "/.* " .. worktree_path
		os.execute(copy_all_cmd)
		os.execute(copy_hidden_cmd)
	end
end)

Two commands are used as 1 links the secrets and the other dotfiles (not sure why the first one doesn't link the dotfiles )

Example

  1. Nvim a fresh --bare clone
  2. Create a worktree, it will work and symlink everything
  3. Create a new worktree, symlink will be broken as the current dir is not root but the new worktree

The issue can be avoided by reopening the project but that adds a lot of friction to the workflow. The problem stems from the inability to get the project root dir

Does anyone have a similar use case and a more elegant solution? As my current idea is to hardcode the root dir

Buffer is not changing after switch in branch with similar names

Hi, today i was trying to switch between to branches with similar names. In my specific case they were cancel-mail-fix and cancel-mail-fix-refactor.
Basically I could go from cancel-mail-fix to cancel-mail-fix-refactor and my buffer will update but not the other way.

I tried to reproduce the error in new bare repo and this were my results. The branches were named as follow:

  • master
  • a
  • a-d

Results

  • master to a OK
  • master to a-d OK
  • a to master OK
  • a to a-d OK
  • a-d to master OK
  • a-d to a ERROR

Basically as you can see i went back and forth between the 3 branches and the buffer was updating correctly in all cases except when i was trying to go from a-d to a. In that case I got stuck in branch a-d.

I look at the logs but they were empty, if someone can tell me what to do in other to log everything I am happy to try again and provide the logs

Working directory doesn't change before `on_tree_change` handler is fired?

I created the following on_tree_change handler:

local harpoon_term = require("harpoon.term")
local Worktree = require("git-worktree")

local on_create_commands = {{
    signal_file = '../shared/config/application.yml',
    cmd = 'ln -s $(ruby -e \'puts File.expand_path("../shared/config/application.yml")\')  $(ruby -e \'puts File.expand_path("./config/application.yml")\')',
    message = 'Application config found, symlinking it'
  }, {
    signal_file = '.tool-versions',
    cmd = 'asdf install',
    message = 'ASDF config detected, installing versions'
  }, {
    signal_file = 'yarn.lock',
    cmd = 'yarn',
    message = 'Yarn detected, running yarn install'
  }, {
    signal_file = 'package-lock.json',
    cmd = 'npm i',
    message = 'NPM detected, running npm install'
  }, {
    signal_file = 'Gemfile.lock',
    cmd = 'bundle',
    message = 'Bundler detected, running bundle install'
  }}

Worktree.on_tree_change(function(op, metadata)
  if op == Worktree.Operations.Create then
    vim.fn.execute('cd ' .. vim.fn.getcwd() .. '/' .. metadata.path)

    commands_to_run = {}

    for _, command in ipairs(on_create_commands) do
      if vim.fn.filereadable(vim.fn.getcwd() .. '/' .. metadata.path .. '/' .. command.signal_file) then
        table.insert(commands_to_run, command.cmd)
      end
    end

    if #commands_to_run > 0 then
      vim.fn.execute('split')
      harpoon_term.gotoTerminal(1)
      harpoon_term.sendCommand(1, table.concat(commands_to_run, ' && ') .. " && exit \n")
      vim.fn.execute('10000') -- go to the bottom of the buffer so it will auto-scroll
    end
  end
end)

I had to execute cd manually because my working directory wasn't changing before the handler fired. Is that intentional, an oversight, or a bug?

Sync worktrees with vim session files

My usual work flow consist of several repo clones and one neovim session in each. To mimick this and allow for switching between work tasks more seamlessly it would be interesting to save and load vim sessions when switching worktrees.

That is to keep:

  • worktree:feature/<some set of buffers>
  • worktree:review/<some other set of buffers>

For a "review" it is not as interesting to keep a memory for opened buffers, but for the "feature" worktree there is - to be able to quickly go back to the previous working position.

Base directory for worktrees

First of all, wanted to thank prime for making this amazing plugin, I'm using it all the time now. Life safer ๐Ÿ‘

So I have set up a git alias that clones a bare repo and puts all the base config inside a folder called ".bare" and the idea is that the worktrees would sit outside the ".bare" folder.

Like this:

project
โ””โ”€โ”€โ”€.bare
|  .git
โ””โ”€โ”€โ”€ worktree-1
โ””โ”€โ”€โ”€ worktree-2

The plugin as far as I know doesn't have a way of changing the base directory for worktrees. So currently I'm having to manually specify a sub path like "../worktree-1"

I have done some playing around locally and managed to add the base_directory property as an option and I will create a pull request later.

Telescope bug

apparently i did not fully test the telescope integration with my last PR, it it not showing any worktrees when opening in a bare repo, will look into it

Current workflow requires opening neovim in the git root

I think we can fix this to allow to open neovim in anywhere and have the plugin look for the git/worktree dir. We should also allow opening with a sub-folder.

this issue has a similar fix as with #24 where when we switch we need to know the previous and next git folder

Additional origin added for Head and Merge

I have occassionally problem when I'm creating new worktree, using the telescope extension to do that.
I try to describe the issue and if someone have knowledge what I'm doing wrong and could tell me how to fix it.

Working one

When it successfully creates new worktree I can see that following infos are correct when looked with vim-fugitive:

Head: fix/jumping-frog
Merge: origin/fix/jumping-frog

And this works as wanted; able to see correct history of Git, git log and so on.

Broken one

When it is broken one, it does not say any error or so but the infos are somehow messed as it puts additional origin as following:

Head: origin/feature/cooling-box
Push: origin/origin/feature/cooling-box

Using Telescope extension

This is how I call the telescope extension:

nnoremap <silent> <Leader>G :lua require('telescope').extensions.git_worktree.create_git_worktree()<CR>

Then I choose wanted branch and press Enter. I will leave the Path to subtree as empty (I have tested to give it a path, but same issue exists.)
I wait that it has done it's thing "Running post switch callbacks" etc.

After this I can confirm the issue by looking the git log and it does not show the changes of that branch, but instead the default branch of the repo, develop.
And when looking the status with vim-fugitive, the additional origin was added.

Unable to `cd` into worktree directory.

I am unable to cd into a new worktree directory if it contains a # character.

It attempts to create the worktree but is unable to cd into the path. It also looks like it is not correctly tracking the remote branch.

1 / 2: Checking for worktree /path/to/worktree-root/origin/feature/issue#511
Error executing vim.schedule lua callback: ...packer/start/git-worktree.nvim/lua/git-worktree/init.lua:143: Vim(cd):E194: No alternate file name to substitute for '#': cd /path/to/worktree-root/origin/feature/issue#511

Telescope git_worktrees error (Expected lua number parse_line)

Hi Prime, love your work!
Huge fan from Spain :3

I'm trying to use the Telescope git_worktrees functionality but I'm getting this error:
image

FYI git-worktree-nvim.log is empty.

I'm trying to figure out if is something wrong with my telescope config but the create_git_worktree extension works perfectly.

Any tip?
Thanks in advance.

Pd. Im using NvChad so pasting my config could be confusing. Just want to know if this error is known by you or if not, will talk with NvChad community.

bug? nvim quits on_tree_change when the nvim-tree plugin is installed

I was trying the nvim-tree plugin which is a nerdTree-like but 100% lua.
I know you are a netrw user but some of us mere mortals like the fuzz and whistles of those file browsers.
Also given that you're THE Primeagem coconut oil supreme vim master, this is most likely a nvim-tree bug, of course. But I though I'd let you know anyway.
For now I've fixed the problem by uninstalling nvim-tree. ;-)
Thanks for this great plugin!

missing License

could you add a license for those of us that have company policy around software used?

module 'telescope._extensions.git_worktree' not found on :PlugInstall

I did :PlugInstall to your neovim config and it looks all OK

Screenshot 2022-03-01 at 11 10 32 PM

which basically also has require("telescope").load_extension("git_worktree") in telescope.lua as mentioned in the readme.

image

But, I still get the following error on opening any file. How do I make it this extension work?

Here's the traceback for reference:

no field package.preload['telescope._extensions.git_worktree']
no file './telescope/_extensions/git_worktree.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/luajit-2.1.0-beta3/telescope/_extensions/git_worktree.lua'
no file '/usr/local/share/lua/5.1/telescope/_extensions/git_worktree.lua'
no file '/usr/local/share/lua/5.1/telescope/_extensions/git_worktree/init.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/lua/5.1/telescope/_extensions/git_worktree.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/lua/5.1/telescope/_extensions/git_worktree/init.lua'
no file './telescope/_extensions/git_worktree.so'
no file '/usr/local/lib/lua/5.1/telescope/_extensions/git_worktree.so'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/lib/lua/5.1/telescope/_extensions/git_worktree.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './telescope.so'
no file '/usr/local/lib/lua/5.1/telescope.so'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/lib/lua/5.1/telescope.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
...lugged/telescope.nvim/lua/telescope/_extensions/init.lua:10: in function 'load_extension'
...lugged/telescope.nvim/lua/telescope/_extensions/init.lua:62: in function 'load_extension'
...dp/.config/nvim/lua/theprimeagen/telescope.lua:33: in main chunk
[C]: in function 'require'
/Users/dp/.config/nvim/lua/theprimeagen/init.lua:1: in main chunk
[C]: in function 'require'
[string ":lua"]:1: in main chunk
Error detected while processing /Users/dp/.config/nvim/plugin/harpoon.vim:
line    1:
E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'theprimeagen'
stack traceback:
[C]: in function 'require'
[string ":lua"]:1: in main chunk
Error detected while processing /Users/dp/.config/nvim/plugin/refactoring.vim:
line    1:
E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'theprimeagen'
stack traceback:
[C]: in function 'require'
[string ":lua"]:1: in main chunk
line    3:
E5108: Error executing lua [string ":lua"]:1: module 'refactoring' not found:
no field package.preload['refactoring']
no file './refactoring.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/luajit-2.1.0-beta3/refactoring.lua'
no file '/usr/local/share/lua/5.1/refactoring.lua'
no file '/usr/local/share/lua/5.1/refactoring/init.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/lua/5.1/refactoring.lua'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/share/lua/5.1/refactoring/init.lua'
no file './refactoring.so'
no file '/usr/local/lib/lua/5.1/refactoring.so'
no file '/usr/local/Cellar/luajit-openresty/2.1-20220111/lib/lua/5.1/refactoring.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
[string ":lua"]:1: in main chunk
Error detected while processing /Users/dp/.config/nvim/plugin/telescope.vim:
line    1:
E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'theprimeagen'
stack traceback:
[C]: in function 'require'
[string ":lua"]:1: in main chunk

Make checking out same branch possible [feature request]

Every so often, this trips me up; I try to add a new worktree, to checkout a branch that I have already checked out elsewhere. The result is an error from git; cannot checkout the same branch twice. I understand from the linked SO thread that this is not possible, but - sometimes I really want to checkout that commit anyway, and there are a lot of reasonable options, but all of these are manual:

  • still checkout that commit, but as detached head (I can make a branch later, or switch to the other worktree, show the reflog and reset hard to the new commit to "pull it in")
  • try deleting the other worktree, but ask again if that will need a force (due to local changes)
  • detach the other worktree from the branch
  • create a different local branchname tracking the same remote
  • abort (currently behaviour)

So my proposal is to add a menu when this error is encountered, so that the above can be done automatically.

Telescope create branch filter

When you use telescope to create a worktree filter out branches that already have worktree that should cause an error if you did create them

Execute commands on Worktree changes

Hello there

I've been trying how to execute custom commands when worktree changes, the docs say that this is possible using Worktree.on_tree_change, I'm not that expert in these configurations, where do I have to add these functions? I believe I'll need to create a Lua file and import it from the init.vim?

If somebody has already done something similar, will be amazing to have an example with the paths used!

Thank you so much and have an amazing day!

fatal: A branch named 'master' already exists.

This works to checkout my remote "master" branch in the "feat-69" path:

-- Creates a worktree.  Requires the path, branch name, and the upstream
-- Example:
:lua require("git-worktree").create_worktree("feat-69", "master", "origin")

But if I try:

:lua require("git-worktree").create_worktree("otherpath", "master", "origin")

to checkout the same "master" branch under "otherpath" I get this error:
fatal: A branch named 'master' already exists.

What am I doing wrong?

Why is the path metadata different between operations?

Operations.Switch has a metadata.path which is a valid path, and Operations.Create has a metadata.path that is just the new worktree directory name. What is the best way to convert that directory into its path?

vim.fn.getcwd() .. '/' .. metadata.path works as long as my current working directory is the bare repo, but I suspect it won't if I'm working in a different worktree already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.