git-worktree.nvim icon indicating copy to clipboard operation
git-worktree.nvim copied to clipboard

Create hook receives incomplete path

Open halfdan opened this issue 2 years ago • 6 comments

The switch and delete hook receive the absolute path to the worktree whereas the Create hook only receives the relative path. This is inconsistent. It's useful to consolidate this to always pass the absolute path as it can then be used as cwd in downstream jobs.

halfdan avatar Oct 19 '22 13:10 halfdan

I fixed the issue in my on_tree_change callback by making sure to use an absolute path. Path is from require('plenary.path') and Path:new():absolute() returns the current working dir (at least for me).

  -- If we're dealing with create, the path is relative to the worktree and not absolute
  -- so we need to convert it to an absolute path.
  local new_path = metadata.path
  if not Path:new(new_path):is_absolute() then
    new_path = Path:new():absolute()
    if new_path:sub(-#'/') == '/' then
      new_path = string.sub(new_path, 1, string.len(new_path) - 1)
    end
  end

Hope that it helps 🙏

bjufre avatar Nov 11 '22 16:11 bjufre

Hi @bjufre Yup, ended up doing something similar. Would be nice if this was made more consistent across the board. I'm not sure if @ThePrimeagen actively maintains this repo though.

halfdan avatar Nov 12 '22 20:11 halfdan

I don't think so; my PR and others have been sitting unreviewed for a while as well; I'd be happy to submit my PR to your fork instead, @halfdan - we need to move on and use each other's improvements.

TamaMcGlinn avatar Nov 18 '22 11:11 TamaMcGlinn

@TamaMcGlinn let's do it - I'll spend some time to cherry-pick existing PRs and get them merged into my fork where appropriate.

halfdan avatar Nov 18 '22 12:11 halfdan

@halfdan I did see we don't technically have permission; it seemed implied, for my part, since he did a video on git-worktree.

TamaMcGlinn avatar Nov 18 '22 12:11 TamaMcGlinn

@TamaMcGlinn Sent an email to @ThePrimeagen to ask whether he could add people as contributors to the repo. I'll give him some time to respond before moving forward with the fork.

halfdan avatar Nov 18 '22 12:11 halfdan