Visual Studio Extensibility: Get the Git repository's path from Team Explorer's Git Commit Details page

冷暖自知 提交于 2021-02-07 19:29:59

问题


I am adding Git integration to my Visual Studio extension Diff All Files, which allows for quickly diffing (i.e. comparing) all files in the Team Explorer window with a previous version. I have it working with the Git Changes page (in Team Explorer), since when I get the Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt service the files in it's IncludedChanges property contain the full file path on disk. However, when working with the Git Commit Details page I get the Microsoft.TeamFoundation.Git.Controls.Extensibility.ICommitDetailsExt service, whose Changes property only contains the file paths relative to the git branch.

I'm using the LibGit2Sharp library to interact with the Git repository, and in able to access the git repository LibGit2Sharp requires the path to a file in the repository. Since the ICommitDetailsExt Changes property only contains file paths relative to the git repo, I don't know how to get the path to the Git repo (so I can retrieve previous versions of the file to compare against).

At first I thought that I could just get access to the path to the solution file using the DTE object, but realized it's possible to view pending changes and previous commits to a Git repo from Team Explorer without have the solution itself open, so that won't work.

So how can I know what Git repository the Git Commit Details page is showing commits from? None of the other properties on the ICommitDetailsExt service seem to have the repository information that I'm after (i.e. the full file path to a file in the repo). Is there a different service I could be getting that would give the Git provider information?

I have also posted this question on the MSDN forums in hopes the Microsoft can perhaps provide an answer.

Thanks in advance.


回答1:


While maybe not ideal - one option (for VS 2013 Update 3+ and VS 2015), is to use the IGitExt extensibility point to get the current active repository. This was added in Visual Studio 2013 Update 3, so this would not work for earlier clients. IGitExt contains a property to get the current ActiveRepositories (which currently will only contain a single item).

I did not find documentation on msdn for this (yet), but you can look the GitHub for Visual Studio extension to see how they use it for an example of getting the IGitExt service and accessing the ActiveRepositories property.



来源:https://stackoverflow.com/questions/32303790/visual-studio-extensibility-get-the-git-repositorys-path-from-team-explorers

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