olimorris / persisted.nvim

💾 Simple session management for Neovim with git branching, autoloading and Telescope support
MIT License
437 stars 26 forks source link

Git branch not detected in subdirectories of a git repo #21

Closed HumblePresent closed 2 years ago

HumblePresent commented 2 years ago

If a session directory is a subdirectory of a git repo rather that the top level directory of the repo, the git branch for the session will not be properly detected because the presence of a .git directory, which only exists in the top level, is used to determine if a directory is tracked in git.

olimorris commented 2 years ago

Sorry I'm failing to understand what you mean by this. Can you explain your point with an example directory structure? From what you've said I've inferred the below:

main_folder/
 L .git/
 L code_base/
   L .git/
HumblePresent commented 2 years ago

Sorry I will try to explain with an example. Here is a simple git repo with several subdirectories

toplevel_dir/
  L .git/
  L subdir1/
    L source1.lua
    L source2.lua
  L subdir2/

If I want to create a session only in the subdir1 directory it will not be detected as being tracked by git by this plugin because it does not contain a .git subdirectory. Therefore, the default and potentially incorrect branch name will be appended to its session file name and a new session will not be created when switching to a different branch the way it would with a session in toplevel_dir. PR #22 fixes the issue by detecting git-tracked directories with git rev-parse rather than checing for a .git subdirectory.

dbatten5 commented 1 month ago

Hi, I'm having issues similar to this. If I open nvim from a subdirectory of a git repo then the git branch isn't appended to the session file name. If I open nvim from the root of the git repo then it is appended. Any advice?