Comments (16)
was this addressed by #29 ?
I feel like you mentioned this.
from git-worktree.nvim.
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.
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.
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.
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.
Should we also move this convo to #29?
from git-worktree.nvim.
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.
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.
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.
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.
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.
changed so it finds the git root when calling create. switch, or delete.
from git-worktree.nvim.
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.
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.
@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.
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)
- Add additional "pre" hooks HOT 1
- Create hook receives incomplete path HOT 6
- Deleting current worktree messes things up
- Is this project dead?
- attempt to index local 'selection' when creating new worktree with Telescope
- Create a branch/tree based on another branch
- Getting error with telescope git_worktrees() HOT 12
- cannot switch worktree when space in directory name HOT 1
- git-worktree v2 HOT 9
- Git Work trees Auto Merging master / Not setting branches correctly
- telescope.create_git_worktree cannot fetch origin when working with passphrase protected ssh-keys HOT 1
- Error when opening a worktree with an empty current buffer
- No worktrees with Telescope 0.1.6 HOT 7
- Changing worktree while having active LSP Clients
- [Adding vim docs]Should add docs to this thing.
- Execute commands on Worktree changes HOT 2
- Copy over git ignored files between worktrees HOT 1
- Open worktree in a new tab and retain the working directory of the old tab
- Base directory for worktrees
- Telescope git_worktrees error (Expected lua number parse_line) HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from git-worktree.nvim.