How to access the api for git in visual studio code

混江龙づ霸主 提交于 2019-12-06 01:04:03

问题


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


回答1:


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

...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];


来源:https://stackoverflow.com/questions/46511595/how-to-access-the-api-for-git-in-visual-studio-code

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