ctrlp.vim icon indicating copy to clipboard operation
ctrlp.vim copied to clipboard

git submodules use top most .git as root

Open mentaal opened this issue 4 years ago • 2 comments

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

mentaal avatar Dec 15 '20 17:12 mentaal

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:

  • How to tell CtrlP that he is in a submodule as even git can't tell that, it's a one way relationship where the project tracks the submodule, but the submodule has no idea it's part of a bigger project
  • How to tell CtrlP to Not try look for a global project if it's already in MAINPROJECT, otherwise it would find my HOME and try indexing that, but MAINPROJECT is not a submodule of HOME (it's ignored)
  • How to tell CtrlP to keep going all the way up to MAINPROJECT if i'm in SUBSUBMODULE, and not stop at SUBMODULE
  • ...

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

  • when you start vim, look for '.git' file in current directory, save that consider it as the MAINPROJECT, but this would be problematic if you open files from different projects in vim, or if you open vim in a directory that contains your projects but is not itself versionned (the projects directory in my example)
  • you have a per-directory configuration of CtrlP but that is no longer CtrlP's responsibility
  • let CtrlP keep track of main projects and submodules in all your projects, this would probably slow it down considerably and be somewhat counter-intuitive as it would then act differently on different directories and different versionning systems.

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

AlexisFinn avatar Jan 02 '21 10:01 AlexisFinn

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.

mentaal avatar Jan 06 '21 09:01 mentaal