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

fix:🐛 paths not normalized for windows #131

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GustavEikaas
Copy link

@GustavEikaas GustavEikaas commented Nov 27, 2024

Description

Running :lua require("git-worktree").create_worktree("nvim-btw","main","origin") on windows results in an error

The has_worktree function does not work on windows. When it tries to compare the output from git worktree list with the calculated path for the newly created worktree it does not get a match.

After adding some print statements, i see the following.

## init.lua #L229
{                                                                                                                                              
  case = "worktree_path:absolute",                                                                                                             
  data = "C:/Users/Gustav/repo/test/cli-devkit.git/abffff",                                                                                    
  path = "C:/Users/Gustav/repo/test/cli-devkit.git\\abffff"                                                                                  
} 

Reproduce

  1. Use windows
  2. Clone a bare repo
  3. Open neovim btw
  4. Run :lua require("git-worktree").create_worktree("nvim-btw","main","origin")
    You will recieve the following error message
    image

Additional

My code only normalizes the path but it is worth considering using vims inbuilt api for concatenating paths
The call to :absolute() seems redundant on windows as it returns an absolute path but perhaps not on linux?

- vim.fs.normalize(Path:new(string.format("%s" .. Path.path.sep .. "%s", git_worktree_root, path)):absolute())
+ vim.fs.joinpath(git_worktree_root, path)

@GustavEikaas GustavEikaas changed the title fix: paths not normalized for windows fix:🐛 paths not normalized for windows Nov 27, 2024
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