3

This is more of a best practice question, as we already have one solution in place, yet I am curious as to whether there are better ways of solving this.

Our projects are divided into 1 huge base project, that all other projects depend on and sub-projects. When building a sub project, I therefore also need to check out that one. In a TFSVC-build, this was possible on the "source" tab of the build definition, where you could specify exactly which projects you wanted the build agent to get for you.

In git (and VNEXT), this tab is gone, and instead there is only the option to specify a branch of your current repository. We solved this by adding a powershell-script to every project, that simply runs "git clone mainproject", granting the same effect as before.

Should our main project URL ever change, this would, however, mean we had to change this script in every customer project, which (while not impossible) would be tedious.

Has anyone got experience of something similar and has found a better way of doing this?

Nicholas DiPiazza
  • 10,029
  • 11
  • 83
  • 152

1 Answers1

2

You could add your main project as a submodule in each of your other projects

cd /path/to/otherproject
git submodule add -b master -- https://url/of/main/project

A git clone --recursive of that other project would automatically clone your main project as well, as a subdirectory.
As described in "git submodule tracking latest", that main project submodule would track the latest of its upstream repo master branch at each git submodule update --remote.

Since git-tfs doesn't support submodule yet, you would need to fall back to command-line for that.


Note: as Daniel Mann mentions in the comments:

TFS supports multiple repositories in one team project. There's no need to have each thing in its own team project.
That is actually counter to current project organization guidance

That means the idea of a submodule per project, while being a valid "git" solution, might not be the best one in a TFS environment.

Daniel mentions the blog post "Many Git Repositories, but one Team Project to rule them all" from Willy-P. Schaub

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Well, in that case I'm just swapping one script for another. Especially since submodules link to commits, and would therefore need an upgrade each time. –  Aug 23 '15 at 15:36
  • 1
    @submarines no, you can link a submodule to a branch (http://stackoverflow.com/a/9189815/6309, also http://stackoverflow.com/a/18799234/6309): a `git submodule update --remote --recursive` would update the submodule to the latest of a branch automatically for you. – VonC Aug 23 '15 at 15:37
  • That does it! Thank you! –  Aug 23 '15 at 15:46
  • @submarines I have edited the answer to make the `-b master` option more visible when using submodule. – VonC Aug 23 '15 at 15:48
  • It's also worth noting that TFS supports multiple repositories in one team project. There's no need to have each thing in its own team project. That is actually counter to current project organization guidance. – Daniel Mann Aug 23 '15 at 16:13
  • @DanielMann Good point. I have included your comment in the answer for more visibility. Do you have a TFS documentation link illustrating that multiple git repos support? – VonC Aug 23 '15 at 16:20
  • Here's an example: http://blogs.msdn.com/b/willy-peter_schaub/archive/2014/11/19/many-git-repositories-but-one-team-project-to-rule-them-all.aspx – Daniel Mann Aug 23 '15 at 16:29
  • @DanielMann Great! Thank you. I have include the link in the answer as well. – VonC Aug 23 '15 at 16:31