kien / ctrlp.vim

Fuzzy file, buffer, mru, tag, etc finder.
kien.github.com/ctrlp.vim
7.26k stars 677 forks source link

git submodules use top most .git as root #792

Open mentaal opened 3 years ago

mentaal commented 3 years ago

Hi All, When using git submodules, is it possible to tell ctrlp to use the top most .git to indicate the project root? I find it frustrating when I'm in a parent file, ctrl-p down into a submodule file and then I can no longer ctrlp back up to a parent project file.

Thanks

AlexisFinn commented 3 years ago

honnestly I also find this a nuisance but I fail to see how it could be implemented. The project is aware it has submodules, but the submodules themselves are not aware they are part of a bigger project, so how would CtrlP detect this ?

ex:

HOME = /home/alexis/.git -> my home folder is versionned for keeping my config files, wallpapers and watnot, I avoid ctrlP when editing something in my home as it will take forever to index as you can imagine and is quicker an less ressource intensive to just directly open the files I want

MAINPROJECT = /home/alexis/projects/MainProject/.git -> this i my project directory, it contains submodules and ctrlP works fine

SUBMODULE = /home/alexis/projects/MainProject/src/submodule/.git -> this is a submodule of MAINPROJECT and when I ctrlP into it then I can't ctrlP back out wich is a nuisance

SUBSUBMODULE = /home/alexis/projects/MainProject/src/submodule/lib/subsubmodule/.git -> a submodule in a submodule ? yes, why not, may not be the prettiest pattern but then again having a single monolithic project is not pretty either so I would consider this to be ok in many cases

Problems:

I can see a few ways of going about this but none very good

Frankly I think the best solution would be a per-project vim configuration as that would make the most sense and avoid breaking anyone's workflow/use case, but I think you'll have to look elsewhere for that as it would have nothing to do with CtrlP

mentaal commented 3 years ago

Hi @AlexisFinn,

One possible solution would be such an algorithm:

  1. When invoking CtrlP, it could walk up the directory structure in search of parent directories containing a .git in much the same way as it does already.
  2. Once a candidate root directory is found, save it but keep walking up the hierarchy. If another candidate root directory is found containing an additional marker file such as .ctrlp_root or whatever, treat that as the root and stop walking. Otherwise, if the directory structure root is reached, just use the first (nearest) candidate parent found in (1).

This way, in your example, your home directory would safely not be treated as the project root, whether you marked /home/alexis/projects/MainProject/ or not.