Skip to content

Allow blink.lib to be submodule #27

Description

@amerlyq

I manage my plugins myself as submodules, without pkg-mgrs.

  • /d/plugins/ repo
  • cloned blink.lib/cmp into /d/plugins/nvim/all
  • then relative symlinks from there to /d/plugins/nvim/{lazy,preload}/pack/startup/start/blink.{lib,cmp}

Attempt to put require('blink.cmp').build():pwait() into ~/.config/nvim/init.lua results in:

Error in UIEnter Autocommands for "*":
 blink.cmp  Failed to build blink.cmp native library: Failed with exit code 101: error: could not find `Ca
rgo.toml` in `/d/plugins` or any parent directory

Probably this is fix:

diff --git a/lua/blink/lib/native/init.lua b/lua/blink/lib/native/init.lua
index 3b74ca5..891e401 100644
--- a/lua/blink/lib/native/init.lua
+++ b/lua/blink/lib/native/init.lua
@@ -155,7 +155,7 @@ end
 --- @param path string Path to the repository root or some path inside the repository
 --- @return string? git_repo_root Path to the repository root
 function native.git_repo_root(path)
-  local git_dir = vim.fs.find('.git', { upward = true, path = vim.fs.normalize(path), type = 'directory' })[1]
+  local git_dir = vim.fs.find('.git', { upward = true, path = vim.fs.normalize(path) })[1]
   if not git_dir then return end
   return vim.fn.fnamemodify(git_dir, ':h')
 end
@@ -163,35 +163,6 @@ end
 --- @param path string Path to the repository root or some path inside the repository
 --- @return string commit_hash For example 'e5678fe566e86553403b3129a3684389c84fafb5'
 function native.git_commit(repo_root)
-  --- @param p string
-  --- @return string?
-  function read_file(p)
-    local fd, err = vim.uv.fs_open(p, 'r', 438) -- 438 = 0666
-    if not fd then error(err) end
-    local content = vim.uv.fs_read(fd, 1024, 0)
-    vim.uv.fs_close(fd)
-    return content
-  end
-
-  -- Read HEAD
-  local head_path = repo_root .. '/.git/HEAD'
-  local head_content = read_file(head_path)
-  if not head_content then error('Failed to read ' .. head_path) end
-  head_content = vim.trim(head_content)
-
-  -- If HEAD is a direct commit hash (detached HEAD)
-  if head_content:match('^%x+$') then return head_content end
-
-  -- HEAD contains a ref, e.g. "ref: refs/heads/main"
-  local ref = head_content:match('^ref: (.+)$')
-  if ref then
-    -- Try to read the loose ref file (e.g. .git/refs/heads/main)
-    local ref_path = repo_root .. '/.git/' .. ref
-    local ref_content = read_file(ref_path)
-    if ref_content then return vim.trim(ref_content) end
-  end
-
-  -- Fallback to git CLI
   local result = vim.system({ 'git', 'rev-parse', 'HEAD' }, { cwd = repo_root }):wait(1000)
   if result.code ~= 0 or result.stdout == nil then error('Failed to get git commit: ' .. (result.stderr or '')) end
   return vim.trim(result.stdout)

Otherwise it fails and then becomes "loop or previous load error"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions