如何在visual studio代码中访问git的api [英] How to access the api for git in visual studio code
问题描述
我想在我的一个扩展中使用 vscode git api 来执行 git clone 和其他任务.是否可以从 vscode api 访问?代码在这里.. api
I want to use the vscode git api in one my extension to do git clone and other tasks. Is it accessible from the vscode api ? The code is present here.. api
推荐答案
Twitter 来救援!我在那里询问并指出这里的 API 定义:https://github.com/Microsoft/vscode/blob/master/extensions/git/src/api/git.d.ts
Twitter to the rescue! I asked there and was pointed to the API definitions here: https://github.com/Microsoft/vscode/blob/master/extensions/git/src/api/git.d.ts
...这里有一个例子:https://github.com/Microsoft/vscode-pull-request-github/blob/master/src/extension.ts#L53
...and an example here: https://github.com/Microsoft/vscode-pull-request-github/blob/master/src/extension.ts#L53
// Import the git.d.ts file
import { API as GitAPI, GitExtension, APIState } from './typings/git';
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git').exports;
const api = gitExtension.getAPI(1);
const rootPath = vscode.workspace.rootPath;
const repository = api.repositories.filter(r => isDescendant(r.rootUri.fsPath, rootPath))[0];
这篇关于如何在visual studio代码中访问git的api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!