简体   繁体   English

Visual Studio可扩展性:从团队资源管理器的Git Commit Details页面获取Git存储库的路径

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

I am adding Git integration to my Visual Studio extension Diff All Files , which allows for quickly diffing (ie comparing) all files in the Team Explorer window with a previous version. 我正在将Git集成添加到我的Visual Studio扩展程序Diff All Files ,它允许快速区分(即比较)Team Explorer窗口中的所有文件与先前版本。 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. 我使用Git Changes页面(在团队资源管理器中),因为当我获得Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt服务时 ,其IncludedChanges属性中的文件包含磁盘上的完整文件路径。 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. 但是,在使用Git Commit Details页面时,我得到了Microsoft.TeamFoundation.Git.Controls.Extensibility.ICommitDetailsExt服务 ,其Changes属性仅包含相对于git分支的文件路径。

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. 我正在使用LibGit2Sharp库与Git存储进行交互,并且能够访问git存储库LibGit2Sharp需要存储库中文件的路径。 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). 由于ICommitDetailsExt Changes属性仅包含相对于git repo的文件路径,因此我不知道如何获取Git repo的路径(因此我可以检索要比较的文件的先前版本)。

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. 起初我以为我可以使用DTE对象访问解决方案文件的路径,但是意识到可以在没有解决方案本身打开的情况下查看挂起的更改以及之前对团队资源管理器的Git仓库的提交,以便赢得不行。

So how can I know what Git repository the Git Commit Details page is showing commits from? 那么我如何知道Git Commit Details页面显示的提交来自哪些? None of the other properties on the ICommitDetailsExt service seem to have the repository information that I'm after (ie the full file path to a file in the repo). ICommitDetailsExt服务上的其他任何属性似乎都没有我所拥有的存储库信息(即repo中文件的完整文件路径)。 Is there a different service I could be getting that would give the Git provider information? 是否有一种不同的服务可以为Git提供商提供信息?

I have also posted this question on the MSDN forums in hopes the Microsoft can perhaps provide an answer. 我也在MSDN论坛上发布了这个问题 ,希望微软可以提供答案。

Thanks in advance. 提前致谢。

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. 虽然可能并不理想 - 一个选项(对于VS 2013 Update 3+和VS 2015),是使用IGitExt可扩展性点来获取当前的活动存储库。 This was added in Visual Studio 2013 Update 3, so this would not work for earlier clients. 这是在Visual Studio 2013 Update 3中添加的,因此这对早期客户端不起作用。 IGitExt contains a property to get the current ActiveRepositories (which currently will only contain a single item). IGitExt包含一个获取当前ActiveRepositories的属性(当前只包含一个项目)。

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. 我没有找到关于msdn的文档(但是),但您可以查看GitHub for Visual Studio扩展,看看他们如何使用它来获取IGitExt服务访问ActiveRepositories属性的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM