I have a mercurial repository myProject:
myProject
|- file1.js
|- file2.css
|- useful.js
Now useful.js is a file with a few useful classes in it. I use it in multiple projects and as such it has its own repository:
useful
|- useful.js
|- example.js
|- README
The idea is that other people can check out useful, have alook at the file and the example and readme, and if they like it, they copy useful.js into their own project and make use of it.
Since useful.js is used in a few of my projects, what is the recommended way to keep it in sync? There is a restriction that useful.js must live in the top-level folder myProject, i.e. can’t be nested. This makes it tricky to use subrepositories (and in any case, then I’d get the other files like example.js and README).
The other thing to note is that the useful repo has a few branches: default, version1, and version2. My projects that use useful.js also have branches default, version1 and version2. I’d like to make sure that whenever I switch between branches in myProject, my useful.js switches branches too. If not for that I could probably live with a symbolic link.
This situation doesn’t seem particularly uncommon; how do others handle it? Just write a hook on update to check if I’m switching branches and switch accordingly? Plus hooks on commit, push, pull ? (basically replicate subrepo behaviour for the single file)?
cheers.
It is impossible to add only a part of a repository as a subrepository with Mercurial. Thus you can’t add only a single file from a repository.
Even if your other repository contained only one file, you could’nt add it at the root level either.
You will have to find another way to include your
useful.jsfile. You’re mentionning hooks to do that, but I can’t see a way to do it honestly without some kind of manual work. Personnally, I’ll go with “simplicity” and do everything “by hand”.Concerning the branch switch, there’s no builtin mechanism in Mercurial, but as you said you should be able to do that with a hook on update.