gitvisual-studio-codevscode-extensions

Read current git branch natively using vscode extension


While I am developing an extension for Visual Studio Code (vscode) I have asked myself how to proper read git refs like the current branch using native methods.

My current solutions feels more like a workaround:

Complete method implemented here (forked extension gitHistoryVSCode)

Any other ideas, for example how to access the extension/git methods or model properties?


Solution

  • The native git extension now provides several methods / properties to fetch the current branch as well as all branches

    Check out the git extension api reference here:

    get branch
    https://github.com/microsoft/vscode/blob/1ab31376742390f215736283dfb763e3a13bced9/extensions/git/src/api/api1.ts#L160

    get branches https://github.com/microsoft/vscode/blob/1ab31376742390f215736283dfb763e3a13bced9/extensions/git/src/api/api1.ts#L164