Skip to content

How to automatically set cwd to submodule ? #1148

Discussion options

You must be logged in to vote

I solved it like this for myself. I added the following code to my setup, and that registers the command NeogitRel which is a a drop-in replacement for :Neogit but it always sets cwd to the git root.

        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…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@menash134
Comment options

Answer selected by madskjeldgaard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants