Visual Studio扩展性:从Team Explorer的Git提交详细信息页面获取Git存储库的路径. [英] Visual Studio Extensibility: Get the Git repository's path from Team Explorer's Git Commit Details page

查看:75
本文介绍了Visual Studio扩展性:从Team Explorer的Git提交详细信息页面获取Git存储库的路径.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Git集成添加到我的Visual Studio扩展对所有文件进行区分,可以快速将Team Explorer窗口中的所有文件与以前的版本进行比较(即比较).我可以在Git更改页面(在团队资源管理器中)使用它,因为当我得到 Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt服务的IncludedChanges属性中的文件包含磁盘上的完整文件路径.但是,当使用Git提交详细信息页面时,我得到 Microsoft.TeamFoundation.Git.Controls.Extensibility.ICommitDetailsExt服务,其Changes属性仅包含相对于git分支的文件路径.

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

起初我以为我可以使用DTE对象访问解决方案文件的路径,但是意识到可以在不打开解决方案本身的情况下从Team Explorer查看挂起的更改和以前对Git存储库的提交,这样就行不通了.

那么我怎么知道Git Commit Details页面显示了哪个Git存储库呢?ICommitDetailsExt服务上的其他所有属性似乎都没有我想要的存储库信息(即,存储库中文件的完整文件路径).我可以得到另一种可以为Git提供程序提供信息的服务吗?

我还发布了解决方案

虽然可能不太理想-一种选择(对于VS 2013 Update 3+和VS 2015)是使用IGitExt扩展点来获取当前的活动存储库.这是在Visual Studio 2013 Update 3中添加的,因此不适用于较早的客户端.IGitExt包含用于获取当前ActiveRepositories的属性(当前仅包含一个项目).

我还没有找到有关msdn的文档(但是),但是您可以查看Visual Studio扩展的GitHub,以查看他们如何使用它作为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.

解决方案

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.

这篇关于Visual Studio扩展性:从Team Explorer的Git提交详细信息页面获取Git存储库的路径.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆