Search code examples
gitgit-submodulesjunction

Git clones junctions as normal folder


in my python package (my_package) I am using several submodules (dependancy packages) which are requirements for the my_package. In order to keep the structure clean, I am using junctions to the submodules source files:

repo
    |-- README.md
    |-- setup.py
    |-- my_package
    |       +-- *.py
    |-- submodules
    |       |-- <requirement1>
    |       |-- README.md
    |       +-- <requirement1_sources>
    +-- <requirement1_sources> -> submodule/<requirement1>/<requirement1_sources>

Junctions are created using mklink:

mklink /J <requirement1_sources> submodule/<requirement1>/<requirement1_sources>

In my repo everything works perfectly, submodule updates and package builds work as expected. However, cloning such repository does not work, because junctions are cloned as regular folders and their content does not updates since it now contains copies of files from submodules. I am cloning the repo like this: git clone -c core.symlinks=true --recurse-submodules

Turning junctions into directory symlinks (mklink /D) works, however it requires elevated prompt. Any help appreciated.


Solution

  • Git does not know how to store junctions, and as such, it treats them as regular directories. This is not limited to Windows-specific items such as junctions; it also does not store hard links or, on Linux, notate bind mounts.

    Note that junctions are not symbolic links, and as such, core.symlinks has no effect on them.

    The proper thing to do is use symlinks. However, as you correctly noted, that requires elevated privileges in many cases. Fortunately, in Windows 10, you can enable Developer Mode, which turns off this requirement, and will probably make your life as a developer a little easier.