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
In the Visual Studio IDE, select the Git menu, select Local Repositories, and then select Open Local Repository.
Step 1: Download and install Visual Studio Code in your system using the official website. Step 2: Download and install git in your system using the official website. Step 3: Now create an account on GitHub.
The Testing API allows Visual Studio Code extensions to discover tests in the workspace and publish results. Users can execute tests in the Test Explorer view, from decorations, and inside commands. With these new APIs, Visual Studio Code supports richer displays of outputs and diffs than was previously possible.
Sample code for using git api in vscode extension :
const gitExtension = vscode.extensions.getExtension('vscode.git').exports;
const api = gitExtension.getAPI(1);
const repo = api.repositories[0];
const head = repo.state.HEAD;
// Get the branch and commit
const {commit,name: branch} = head;
// Get head of any other branch
const mainBranch = 'master'
const branchDetails = await repo.getBranch(mainBranch);
// Get last merge commit
const lastMergeCommit = await repo.getMergeBase(branch, mainBranch);
const status = await repo.status();
console.log({ branch, commit, lastMergeCommit, needsSync: lastMergeCommit !== commit });
You also have to update extensionDependencies in you package.json:
"extensionDependencies": [
"vscode.git"
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With