Coder Social home page Coder Social logo

Comments (16)

ThePrimeagen avatar ThePrimeagen commented on September 27, 2024

was this addressed by #29 ?

I feel like you mentioned this.

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

No. And I just updated but that made things worse. Now it doesn't work even if I start vim in the bare git repo directory, because now git_worktree_root is nil rather than the directory which vim starts in.

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

Sorry for the duplicate issue; I did not find #29 but this is exactly that issue. It's just not solved yet.

from git-worktree.nvim.

polarmutex avatar polarmutex commented on September 27, 2024

I am confused , is this solved or is there an issue on the latest master now? the latest master is detecting the git root on my system just want to make sure I did not miss a corner case.

from git-worktree.nvim.

ThePrimeagen avatar ThePrimeagen commented on September 27, 2024

I may also be missing something.

My testing I can create, delete, and switch trees as of now. I use bare repos.

from git-worktree.nvim.

ThePrimeagen avatar ThePrimeagen commented on September 27, 2024

Should we also move this convo to #29?

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

I'm not sure where to move this either; I was thinking #30 at first, since it was the same issue, but then I updated to the latest master (cdcc26d Merge pull request #32 from rudotriton/prompt-title) and now switching doesn't work even if I do start vim in the git root directory. So I guess this really is a new issue, and I will reopen.

I would love to add a failing unit test in a PR, but I don't understand how to even run the unit tests at all; you require("git-worktree") and I guess that should read git-worktree/init.lua but my lua installation just says it can't find git-worktree.lua in various directories.

I will keep debugging this, but in terms of repro steps it's as simple as 'try to change worktrees' using :lua require('telescope').extensions.git_worktree.git_worktrees(), so it is a mystery to me why I am the only one with the problem.

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

I've temporarily fixed this in my own vimrc with this:

fu! Switch_Worktree() abort
  lua require('git-worktree')._find_git_root_job()
  lua require('telescope').extensions.git_worktree.git_worktrees()
endfunction

nnoremap <leader>gww :call Switch_Worktree()<CR>

You are still assuming that the directory which vim initially starts in is within the git project; I tend to start nvim straight in my home directory, and have a Startify menu which means one number press brings me into both file and directory of one of the last places I was editing before. I also change directory all the time when moving about from project to project, so it doesn't make sense to me to call find_git_root_job() once at startup and then never again.

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

I also noticed that when you have 3 worktrees involved, where one is the current CD path, you have a file open which is in the second, but you want to switch to a third one, then git_worktrees() manages to switch the directory, but is not able to open the file afterwards, so it opens the root directory instead. Really the current directory should not be relevant; rather than doing a string substitution to get the relative path from the root of the worktree to the file, we should probably just ask git: !git rev-parse --show-prefix % ?

from git-worktree.nvim.

polarmutex avatar polarmutex commented on September 27, 2024

I see the issue now, calling any of the functions requires you to be in a git repo. with #37 , I want to discuss and think about the best way to add this in. For example, if we use just branch names, we will have no way to know the git repo unless the cwd was a the git repo we want to use.

for what is currently implemented(using path not branch) will the following be good?

For Switch and Delete

  • If the current cwd is a git repo, any call should use that directory
  • If the current cwd is not a git repo, check the path is in a git repo and use that if so
    For Create
  • Always assume we are in a git repo

Then to support #37, we could create new functions that take a branch name and require to be in a git repo

Thoughts?

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

I don't believe the current working directory is ever relevant, and I certainly wouldn't want it to influence the decision of where to jump to. For instance, fugitive also only looks at the actual file you have open, and completely ignores your working directory.

Is it acceptable to add a dependency on the fugitive plugin?

let root_dir = system(fugitive#repo().git_command() . ' rev-parse --git-dir')

Otherwise, grabbing the internals of fugitive would also be more efficient that this; that system call is not necessary since fugitive already knows for each buffer what the git-dir is.

from git-worktree.nvim.

polarmutex avatar polarmutex commented on September 27, 2024

changed so it finds the git root when calling create. switch, or delete.

from git-worktree.nvim.

ThePrimeagen avatar ThePrimeagen commented on September 27, 2024

There is a danger when considering the current file. Which in some sense I would argue is wrong.

You could end up changing all sorts of things like that.

Perhaps this is a mode of operation issue. I will never open up files all around, I'll just be switching worktrees as I do my work. I always open my vim experience from the root, and the starting place, the cwd, is the git root at all times except when I shortcut and go to the branch I really want (which btw still works).

The reason why I don't like only considering current file is that I sometimes edit my vimrc. That is in completely different project and I wont want it to influence anything.

@TamaMcGlinn I think that a unit test showing the break would be the best possible solution to this. If you make a PR with a breaking unit test I am positive I or polar can have a more robust talk about this because I ma still slightly confused of the exact use case you are going for (even when reading it). I know, I am big dumb, and want to support you :)

from git-worktree.nvim.

TamaMcGlinn avatar TamaMcGlinn commented on September 27, 2024

My current workaround is to call fugitive's Gcd prior to switching worktree. It works, but the on_tree_update function I pass does not. I am trying to make it also jump to the same place in the file as where I was before:

fu! Switch_Worktree() abort
  silent execute 'Gcd'
  lua << EOF
  local linenr = vim.api.nvim_win_get_cursor(0)[1]
  local Worktree = require("git-worktree")
  Worktree._find_git_root_job()
  Worktree.on_tree_update = (function(op, metadata)
    vim.cmd('execute "normal! ' .. linenr .. 'G"')
  end)
  require('telescope').extensions.git_worktree.git_worktrees()
EOF
endfunction

nnoremap <leader>gww :call Switch_Worktree()<CR>

the on_tree_update example in the README isn't very helpful, it doesn't seem to show actually reassigning the funcref. I think it would really helpful to be able to pass a lambda to git_worktrees() which is executed just once; my current workaround is actually reassigning a persistent action every time, which isn't really what I mean.

from git-worktree.nvim.

matu3ba avatar matu3ba commented on September 27, 2024

@TamaMcGlinn Your best bet is to use telescope-project andshell out the check if :lcd switched to a worktree and setting it accordingly via script inside git-worktree.

This could require a commit to provide a function that sets the root_dir for git-worktree.

Unfortunately telescope-project has no support for checking if a path is a bare git yet, but it should work nevertheless. And git also does not support finding the root dir inside bare repos, but it is trivial to combine from the aforement checks.

from git-worktree.nvim.

ThePrimeagen avatar ThePrimeagen commented on September 27, 2024

Sorry, I've just been so busy to try to take care of these things. I'll try to take a look at it this week. But I can feel that nfts are going to creep up and take all my time.

from git-worktree.nvim.

Related Issues (20)

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.