vscode-remote-release
vscode-remote-release copied to clipboard
Clone repository with specific branch
Hi, I see many issues/requests about the great feature "Clone repo in Container Volume", but my need is to clone a specific branch in my repo.
The problem is that I have .devcontainer
only in a specific branch, so cloning the repo creates a general container instead of using the customized from the branch.
My suggestion is just allowed to clone https://myrepo#myBranch
or something.
You can use a GitHub branch url, like: https://github.com/microsoft/vscode-azurecli/tree/chrmarti/pipelines
Thanks, but what about other providers?
We are talking about Git, not Github. In my company we still hosting our Git repos in TFS.
Do you want to direct me to the code, so I will learn what can I do?
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 10 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
@chrmarti @egamma I think it should not be too difficult, can you guide me and I will try to solve it myself, instead of waiting two months?
:slightly_smiling_face: This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
@baruchiro the request makes sense but as far as I know there is no common URL format defined at the level of Git.
The git repository picker is extensible
The git extension provides an API to register a remote source provider. The GitHub repository Picker supports to pick a branch
This is the API https://github.com/microsoft/vscode/blob/6b241a6845d17992a5a754d5eaf32fd1824ef74e/extensions/git/src/api/git.d.ts#L259-L259
I have the same concern as in the OP, and I strongly like the solution proposed by @egamma
Ideally we could define the branch name in .devcontainer.json
@fyyyyy That sounds like a different request. The one discussed here is about specifying the branch before the devcontainer.json is available (before the repository is cloned). Could you open a new feature request with additional details on how that branch name would apply?
should be nice to have this feature in .devcontainer
@baruchiro the request makes sense but as far as I know there is no common URL format defined at the level of Git.
The git repository picker is extensible
The git extension provides an API to register a remote source provider. The GitHub repository Picker supports to pick a branch
This is the API https://github.com/microsoft/vscode/blob/6b241a6845d17992a5a754d5eaf32fd1824ef74e/extensions/git/src/api/git.d.ts#L259-L259
I tried making a hack of an extension to see if making an alternate remote source provider that takes a repository clone_url
(as a hack when querying for a list of repositories against the "provider"), some git ls-remote
action to list branches, and getting the Git extension to be returning an additional branch property was usable:
https://github.com/nelsonjchen/non-github-remote-source-provider
It wasn't. There's some weird hardcodedness in "Remote: Containers" that if a some sort of additional branch
property is passed into it alongside the url
, it tries to clone with "/tree/<some branch name>
" appended to the clone_url
which causes 💥 for my test non-GitHub repository at https://gitlab.com/nelsonjchen/dev-container-test. Using the same extension with its GitHub repository counterpart's clone URL works just fine. 🤷♂️ There are bit more notes in the README if one is inclined to see a bit more of what I saw.
Oh well, I can't say I didn't try. I wish I could see what was also going on with "Remote: Containers" but that's closed source.
I made the extension so that my team at my day job might be able to use it to clone with the option to choose a branch from an internal Atlassian Bitbucket repository. I was just testing with GitLab since they happened to be at hand but I realized that they are big enough to also make a RemoteSourceProvider
implementation themselves.
Unfortunately, they don't implement getBranches()
so the "Clone Repository in a Container Volume" command flow halts after being able to pick which URL to use. Thus, I am unable to compare to a pre-existing non-GitHub RemoteSourceProvider
.
FWIW, Atlassian's extension doesn't implement RemoteSourceProvider
from what I can see.
Is there any news on this? @nelsonjchen I just installed the gitlab extension and when starting the "Clone Repository in a Container Volume" flow I don't see Gitlab as an option at all? Or should that not pop up like Github and instead just start once I add a url? If you have a working extension that allows you to select branches for gitlab instances, and would consider sharing it, I'd be very grateful.
Otherwise, I would really love for the remote-container implementation to be able to ask for a branch name after cloning the repo.
Is there any news on this? @nelsonjchen I just installed the gitlab extension and when starting the "Clone Repository in a Container Volume" flow I don't see Gitlab as an option at all? Or should that not pop up like Github and instead just start once I add a url? If you have a working extension that allows you to select branches for gitlab instances, and would consider sharing it, I'd be very grateful.
Otherwise, I would really love for the remote-container implementation to be able to ask for a branch name after cloning the repo.
The GitLab extension doesn't implement the getBranches
API. I tried to implement an extension that could be universal for any Git repository but maybe it's my hack or maybe not, VSCode Remote interprets the "branch
" parameter passed to it incorrectly for non-GitHub repositories.
I think I've already explained this in my posts just right above.
I was hoping to share a working extension, but you can see in my post I've only been able to share a broken one as that's the limit of the API/VSCode Remote's interpretation of the API.
I don't get it. Can't you guys use this command to get the branches in the repository..
git ls-remote --heads <remote-repo-url> | cut -f 2 | cut -c "$(wc -m <<<'refs/heads/')-"
and then this command to clone it?
git clone --branch <branchname> <remote-repo-url>
PS: The pipes to the cut
commands in the first command are to strip away the hashes (cut -f 2
) and the refs/heads/
prefix (wc -m
is to count the number of characters in refs/heads/
. I could have hard-coded this to 12 instead. The cut -c 12-
Strips the first 12 characters from each line of input).
@baruchiro the request makes sense but as far as I know there is no common URL format defined at the level of Git.
The git repository picker is extensible
The git extension provides an API to register a remote source provider. The GitHub repository Picker supports to pick a branch
This is the API https://github.com/microsoft/vscode/blob/6b241a6845d17992a5a754d5eaf32fd1824ef74e/extensions/git/src/api/git.d.ts#L259-L259
@egamma You shouldn't need a common URL format defined at the level of git. Check my previous comment and the git ls-remote
command.
@adriancuadrado We know how to run a git command to clone it with a branch. The issue is that we don't control what git clone
command VS Code Remote puts together and runs. We implement classes such as RemoteSourceProvider
that pass it back values like repo URL and branch name but VS Code Remote interprets that incorrectly and tries to run a bad git clone
command for non-GitHub repositories.
I haven't checked if this is still the case within the past few months but since there are no comments from Microsofties, I'm assuming this hasn't changed.
@adriancuadrado We know how to run a git command to clone it with a branch. The issue is that we don't control what
git clone
command VS Code Remote puts together and runs. We implement classes such asRemoteSourceProvider
that pass it back values like repo URL and branch name but VS Code Remote interprets that incorrectly and tries to run a badgit clone
command for non-GitHub repositories.I haven't checked if this is still the case within the past few months but since there are no comments from Microsofties, I'm assuming this hasn't changed.
@nelsonjchen Wouldn't it be possible to manually run the git commands as a temporary solution until this problem gets fixed and then do things the right way? I'll understand if you prefer waiting and do it right once, but at least we won't have to wait as much to have this feature implemented.
@adriancuadrado I don't know if VS Code Remote has an escape hatch like that. That's probably a question for @egamma and other people on the VS Code team.
https://github.com/microsoft/vscode-remote-release/issues/7363#event-7682393794
Workaround coming down the line? Make devcontainer without having to clone a repo and then do the ol' git clone -b
?
There are lots of workarounds, but this is a still neat lightweight alternative possibly.