You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Iam using the below code to open the Neogit based on the current file that has been opened in Neovim. Note: The directory I started Neovim is a parent directory where there are no git repository.
The Neogit tab window opens and I can stage the file opened.
As soon as I want to commit the stage file by pressing "c-c", then I get the following error.
And When I want to do other operations in Neogit like log "?-l-l" I also get the error.
Anything with ? does not work for me, although I started the Neogit with cwd properly. Any idea what Iam missing?
Thanks
Ashok
local function find_git_root(filepath)
local function get_folder_from_filepath(fp)
return fp:match("(.*/)")
end
filepath = get_folder_from_filepath(filepath)
-- The Git command to find the top-level directory
local git_cmd = "git -C " .. filepath .. " rev-parse --show-toplevel"
-- Execute the Git command
local git_root = vim.fn.system(git_cmd)
-- Handling errors (if the file is not in a Git repository or other issues)
if vim.v.shell_error ~= 0 then
print("NeogitRel: Error finding Git root: " .. git_root)
return nil
end
-- Trim any newlines from the output
git_root = git_root:gsub("%s+", "")
return git_root
end
local function open_neogit_from_current_file(opts)
opts = opts or {}
local gitroot = find_git_root(vim.fn.expand("%:p"))
if gitroot == nil then
print("NeogitRel: Not in a git repo")
return
end
-- Prepare options
opts = vim.tbl_extend("force", { cwd = gitroot }, opts)
require "neogit".open(opts)
end
-- Register excommand that opens Neogit from the current file
-- The command takes one argument which is passed to Neogit
vim.api.nvim_create_user_command(
'NeogitRel', -- Name of the command
function(opts)
-- Call the local function with the argument
open_neogit_from_current_file(opts.args[1])
end,
{ nargs = '?' } -- Specifies that the command takes one argument
)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi All,
Iam using Neovim 0.10
Iam using the below code to open the Neogit based on the current file that has been opened in Neovim.
Note: The directory I started Neovim is a parent directory where there are no git repository.
The Neogit tab window opens and I can stage the file opened.
As soon as I want to commit the stage file by pressing "c-c", then I get the following error.
And When I want to do other operations in Neogit like log "?-l-l" I also get the error.
Anything with ? does not work for me, although I started the Neogit with cwd properly. Any idea what Iam missing?
Thanks
Ashok
Beta Was this translation helpful? Give feedback.
All reactions