1

I've got a library project that has an associated JavaScript file, that any web sites using the library will have to include.

In the source control, the js file belongs to the library (which is right). However, when running/debugging/changing the application it is really convenient to treat the file as belonging to the web project using the library.

In TFS we handled this by remapping the scripts directory of the library onto the scripts directory of the web project, meaning that when working the project, the js file effectively looks as part of the web project, while it follows the library when branching/merging.

How do I do something similar in git?

Using a build script to copy the file is not a viable solution. It would make live changes while debugging impossible since it would only update the copy, or require a rebuild of the entire app for just a small change to force the file to be copied.

Using "add as link" is not an option either, since the web server isn't reading the project file and won't know of the link and will just return a 404 when the script is requested.

The project is developed in Visual Studio 2012, so any solution must work well together with the project structure in VS.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217

3 Answers3

2

How about just making the library project's Git repository a submodule (or a subtree, if you prefer) of the application's Git repository, and then using a relative path to refer to the library's JavaScript file from the application?

sschuberth
  • 28,386
  • 6
  • 101
  • 146
  • I looked at those, but never got it to work (probably because I don't know git well enough). Can you please elaborate? The library and the application are in the *same* repo (can't change that as I'm working with git-tfs and have to follow the setup the rest of the team uses in tfs). – Anders Abel Sep 01 '13 at 07:41
  • 2
    If the lib and app need to stay in the same repo you're indeed out of luck and cannot use submodules. Also, as Git for Windows [does not yet support file system links](http://stackoverflow.com/a/11664406/1127485) this is not a feasible option either (because, as you say in your own answer, the link has to be created each time the repo is cloned). So I'm currently out of other (good) ideas. – sschuberth Sep 01 '13 at 11:42
1

A workaround is to use ntfs hard links.

mklink /h aliasdir\script.cs realdir\script.cs

Then add aliasdir to .gitignore to prevent git from adding the file twice. The file will now be in one place only (realdir) but can be added from both places.

The con is that the hard links have to be created each time the repository is cloned, it is not a configuration that is possible to check in.

I also tried with symlinks (mklink wihtout /h) first, but Cassini (the ASP.NET development server) doesn't follow them.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217
0

Depending on your number of projects to use this with, you can add the file to another project, but in the add dialog, select to add the file as a link:

Add as link

This will keep the file in its original location, but act as if it was part of the solution (so you can do Content|Copy-Always etc to it), and has the advantage of being source-control agnostic.

Pondidum
  • 11,457
  • 8
  • 50
  • 69
  • Unfortunately that doesn't work for script files, as the web server won't see the link and just return a 404 for any requests for the script. – Anders Abel Aug 30 '13 at 09:47
  • It should do though? If you add the script to the project, and set it as Content/Copy Always it should be copied to the output folder as normal (this is how we manage all our config files at work). Or maybe I have missunderstood the question. – Pondidum Aug 30 '13 at 09:49
  • That would only copy on build, making live changes impossible (or at least hard, having to edit both "real" file and the copy. – Anders Abel Aug 30 '13 at 09:57