Linking git repository to multiple TFS projects

拥有回忆 提交于 2019-12-24 03:28:00

问题


I have a git repository that needs to be shared across multiple other projects as a shared library/common code. The projects using this common code are all TFS projects (TFS2013). I am able to host the git repo in TFS, but cannot figure out how to link the git and TFS repos together without duplication.

The idea I am trying to achieve is identical to git's submodules, where one git repo can be a submodule to N other git repos:

- CommonLib/ (git)
    - src/
    - inc/
- Project1/ (git)
    - src/
    - inc/
    - lib/
         -CommonLib (git submodule)
 - Project2/ (git)
    - src/
    - inc/
    - lib/
         -CommonLib (git submodule)

But I would like to do this when the projects are TFS repositories:

- CommonLib/ (git)
    - src/
    - inc/
- Project1/ (TFS)
    - src/
    - inc/
    - lib/
         -CommonLib (?? How to link ??)
 - Project2/ (TFS)
    - src/
    - inc/
    - lib/
         -CommonLib (?? How to link ??)

Is this possible?

One solution I came up with is just to clone the CommonLib repo into each of the project's lib/ directory and set the upstream remote appropriately. But then I have to check in the git repo into the TFS repo and that seems incorrectly to me.

I would like a developer who makes a source change in CommonLib within Project2, to be able to check in their changes to the git repo automatically when they checkin to TFS. Similar to how one would use a git submodule, where they can commit both the project changes (parent) and the submodule (child) changes in a single git commit from the parent.


回答1:


Yes, it’s possible. You can add submodule for a TFS git repo by git command Line (such as git bash) since TFS IDE (visual studio) can’t well show git submodule but it will improved in the near future.

The commands to add submodule for TFS git repo Project1 (similar with Project2) as below:

git clone http://account:8080/tfs/DefaultCollection/_git/Project1
cd Project1
git submodule add http://account:8080/tfs/DefaultCollection/_git/CommonLib
git push

If the CommonLib is updated and you can update the submodule in Project1 by git submodule update --remote.

Files in submodule can view in local repo. You will only find the latest commit id of submodule on TFS git repo.




回答2:


There is no available tool that does this for you: I would recommend against this approach and I will show you why.

Visual Studio will not help unless you open multiple instance using different .SLN files, and it is up to the developer to manually touch the code and do the operation. You can devise your own command line tool that somehow synch operations on the two version control system by calling in sequence git & tf. You can pick the commit sha from git and add to the TFVC comment. In any case it will be very hard determine which git commit is required by a TFS changeset.

I suggest you instead to move all code to either one of the two version control systems.



来源:https://stackoverflow.com/questions/42960636/linking-git-repository-to-multiple-tfs-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!