fff icon indicating copy to clipboard operation
fff copied to clipboard

"Not in a git repo" returns

Open bogorad opened this issue 9 months ago • 3 comments

fff.nvim find_in_git_root regression

Error

  • In a valid Git repository on Windows, running find_in_git_root() shows:
    • Not in a git repository

Cause

  • find_in_git_root() reads fuzzy.get_git_root() immediately.
  • get_git_root() depends on async initial scan state.
  • On startup, scan state can still be empty, so git_root is nil even in a repo.

Successful mitigation

  • Wait for initial scan before reading git root.
  • If scan is not ready or git_root is empty, fall back to:
    • git rev-parse --show-toplevel in current cwd.
  • This mitigation works in local testing.

Changed code

File: lua/fff/main.lua

function M.find_in_git_root()
  local fuzzy = require('fff.core').ensure_initialized()

  local wait_ok, scan_ready = pcall(fuzzy.wait_for_initial_scan, 5000)
  if not wait_ok then
    vim.notify('Failed to wait for initial scan', vim.log.levels.WARN)
  end

  local ok, git_root = pcall(fuzzy.get_git_root)

  if not scan_ready or not ok or not git_root or git_root == '' then
    local cwd = vim.fn.getcwd()
    local result = vim.system({ 'git', 'rev-parse', '--show-toplevel' }, { cwd = cwd, text = true }):wait()
    if result.code == 0 and result.stdout and result.stdout ~= '' then
      git_root = result.stdout:gsub('%s+$', '')
    end
  end

  if not git_root or git_root == '' then
    vim.notify('Not in a git repository', vim.log.levels.WARN)
    return
  end

  M.find_files_in_dir(git_root)
end

bogorad avatar Feb 16 '26 20:02 bogorad

I picked this up and opened a fix PR: #248\n\nThe patch waits for the initial scan, then falls back to git rev-parse --show-toplevel when the cached git root is still unavailable, which avoids the startup race behind the false 'Not in a git repository' warning.

kuishou68 avatar Apr 04 '26 09:04 kuishou68

PR is now open: #337\n\nIt waits for the initial scan and falls back to git rev-parse --show-toplevel when the cached git root is still unavailable, which avoids the startup race behind the false 'Not in a git repository' warning.

kuishou68 avatar Apr 04 '26 09:04 kuishou68

[triage-bot] LINKED PR: #337 (open) — https://github.com/dmtrKovalenko/fff/pull/337

PR waits for initial scan via wait_for_initial_scan before reading cached git root, then falls back to git rev-parse --show-toplevel when cache still empty. Adds Lua regression tests for startup-race fallback and no-repo warning. Matches mitigation from issue body.

gustav-fff avatar May 20 '26 20:05 gustav-fff