File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed
Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -313,18 +313,21 @@ pcall(require('telescope').load_extension, 'fzf')
313313local function find_git_root ()
314314 -- Use the current buffer's path as the starting point for the git search
315315 local current_file = vim .api .nvim_buf_get_name (0 )
316+ local current_dir
317+ local cwd = vim .fn .getcwd ()
316318 -- If the buffer is not associated with a file, return nil
317319 if current_file == " " then
318- print (" Buffer is not associated with a file" )
319- return nil
320+ current_dir = cwd
321+ else
322+ -- Extract the directory from the current file's path
323+ current_dir = vim .fn .fnamemodify (current_file , " :h" )
320324 end
321- -- Extract the directory from the current file's path
322- local current_dir = vim .fn .fnamemodify (current_file , " :h" )
325+
323326 -- Find the Git root directory from the current file's path
324327 local git_root = vim .fn .systemlist (" git -C " .. vim .fn .escape (current_dir , " " ) .. " rev-parse --show-toplevel" )[1 ]
325328 if vim .v .shell_error ~= 0 then
326- print (" Not a git repository" )
327- return nil
329+ print (" Not a git repository. Searching on current working directory " )
330+ return cwd
328331 end
329332 return git_root
330333end
You can’t perform that action at this time.
0 commit comments