Topic cross posted in mathematica.stackexchange.com
As explained in https://mathematica.stackexchange.com/q/59127/5478 loading packages from custom directories may not be so intuitive. Not to mention absolute lack of documentation of interaction between $Path, PacletDirectoryAdd, paclet's version etc.
Recent update to linked question explains something that hit me hard lately:
If you have MyPackage` (V2) paclet installed in default repo and MyPackage` (V1) in customDir. Then:
PrependTo[ $Path, customDir];
PacletManager`PacletDirectoryAdd @ customDir;
will load MyPackage` V2 from default repo.
I find this unexpected and really problematic
You are working on dev branch on V2, part of testing involves packing it and installing locally, which means there will be V2 in default repo.
Before finishing V2 you need to push a fix to V1 so you create another fix branch from master (V1). You would like to load your code, surprise it loads V2 from default repo despite your changes to $Path and paclet directories.
How to make sure that MyPackage` will be loaded from customDir?
MyPackage` may contain 3rd part packages inside, e.g. MyPackage/WL/GitLink which it loads internally e.g. by temporarily blocking $path and prepending MyPackage/WL. However, GitLink may be already installed locally, newer or older, does not matter, the one from customDir/MyPakcage/WL should be loaded. Which means the solution can be based on fixing the issue for MyPackage only.
p.s. will try to provide a code to play with later.