Given a path of a file or folder that is in a VS Code workspace, is there an API I can use to determine if it’s Git-controlled and look up the associated remote repository URL? This would be for a custom extension.
Question posted in Visual Studio Code
View the official documentation.
View the official documentation.
2
Answers
I am not sure if this answers your question, but if it is something you are working on, there is a hidden git folder in the root folder. ".git" which has a config file with the remote url listed.
Try this code. It gets the workspace folder of the file you are interested in. And then checks if that is one of the git repositories that you have opened – it works for single root or multiroot workspaces where a file may be in a root folder that may or may not be in a git repo.
See also https://stackoverflow.com/a/59442538 and Git integration for Visual Studio Code especially the part about
extensionDependencies
.