Our developers use a mix of Windows and Unix based OS's. Therefore, symlinks created on Unix machines become a problem for Windows developers. In windows (msysgit), the symlink is converted to a text file with a path to the file it points to. Instead, I'd like to convert the symlink into an actual Windows symlink.
The (updated) solution I have to this is:
- Write a post-checkout script that will recursively look for "symlink" text files.
- Replace them with windows symlink (using mklink) with same name and extension as dummy "symlink"
- Ignore these windows symlink by adding entry into .git/info/exclude
I have not implemented this, but I believe this is a solid approach to this problem.
Questions:
- What, if any, downsides do you see to this approach?
- Is this post-checkout script even implementable? i.e. can I recursively find out the dummy "symlink" files git creates?
- Has anybody already worked on such script?
Short answer: They are now supported nicely, if you can enable developer mode.
From https://blogs.windows.com/buildingapps/2016/12/02/symlinks-windows-10/
Easy to overlook with all the other announcements of the "Creator's update", but if you enable Developer Mode, you can create symlinks without elevated privileges. You might have to re-install and make sure support is enabled, as it's not by default.
I was looking for an easy solution to deal with the unix symbolic links on windows. Thank you very much for the above Git aliases. There is one little optimization that can be done to the rm-symlinks so that it doesn't delete the files in the destination folder in case the alias is run a second time accidentally. Please observe the new if condition in the loop to make sure the file is not already a link to a directory before the logic is run.
I use sym links all the time between my document root and git repo directory. I like to keep them separate. On windows I use mklink /j option. The junction seems to let git behave normally:
>mklink /j <location(path) of link> <source of link>
for example:
>mklink /j c:\gitRepos\Posts C:\Bitnami\wamp\apache2\htdocs\Posts
I would suggest you don't use symlinks within the repo'. Store the actual content inside the repo' and then place symlinks out side the repo' that point to the content.
So lets say you are using a repo' to compare hosting your site on *nix with hosting on win. Store the content in your repo', lets say
/httpRepoContent
andc:\httpRepoContent
with this being the folder that is synced via GIT, SVN etc.Then, replace the content folder of you web server (
/var/www
andc:\program files\web server\www
{names don't really matter, edit if you must}) with a symbolic link to the content in your repo'. The web servers will see the content as actually in the 'right' place, but you get to use your source control.However, if you need to use symlinks with in the repo', you will need to look into something like some sort of pre/post commit scripts. I know you can use them to do things, such as parse code files through a formatter for example, so it should be possible to convert the symlinks between platforms.
if any one knows a good place to learn how to do these scripts for the common source controls, SVN GIT MG, then please do add a comment.
It ought to be implemented in msysgit, but there are two downsides:
I did a quick search and there is work being actively done on this, see issue 224.
Here is a batch script for converting symlinks in repository, for files only, based on Josh Lee's answer. Script with some additional check for administrator rights is at https://gist.github.com/Quazistax/8daf09080bf54b4c7641.