Allow specifying any remote ref in git checkout URLs#32502
Allow specifying any remote ref in git checkout URLs#32502mlaventure merged 1 commit intomoby:masterfrom
Conversation
|
Is this a GitHub convention or something used more widely in the git world? |
|
@aaronlehmann It's a convention, I'm not sure how many other sites use it. https://bitbucket.org/site/master/issues/5814/reify-pull-requests-by-making-them-a-ref is issue from bitbucket for adding the same thing. |
|
Hm, yes, looks like it's convenient, but I'm wondering if this is adding too much magic. What's the exact use-case? If this is is for running Docker in CI/CD, I can imagine it's the responsibility of CI/CD to setup the correct URL. So, I'm +1/-1 |
|
@thaJeztah We already support lots of magic for this. For example, we even support |
|
Can't the user just say |
|
@ijc25 That wouldn't work. You have to fetch the remote reference as they are not pulled in clone and can't be checked out. It still defaults to tag and branch so wouldn't break anyone. That ambiguous behavior is kind of builtin to git where refname can mean multiple things and there is a priority order of what is checked out first(tag -> branch -> remote-branch etc). |
|
@tonistiigi I meant that the fall back behaviour should be to try and pull the named things precisely, rather than a massaged version of it. I don't think the particular ambiguity I spoke about is to do with refname fallbacks like you suggest. It is down to the default refspec used on clone, which is In any case someone who wanted PR |
|
Also note that |
|
@ijc25 So you are suggesting that we should not fallback to a PR but to any remote ref? That sgtm, I'll make the change. |
|
@tonistiigi Sorry, for the delay, there were public holiday's here.
Yes. In fact in this "mode" you could just Sadly this (and all the variants of it I tried) doesn't seem to do what I hoped: it needs a manual |
94591a1 to
d76062a
Compare
|
@ijc25 Updated. I also noticed that when no ref is specified we did a clone with Maybe you have a better idea for https://github.com/moby/moby/pull/32502/files#diff-eac74eb810b282bbc18d5db1cca37b87R92 , I'm currently doing a checkout by name first so it wouldn't break anyone depending on reading current branch name from |
|
Looks good to me, at least by code inspection. Using
I was a bit surprised this worked, but I checked and TIL that This invalidates one suggestion I was about to make which was to skip the Some of this is perhaps a bit subtle, maybe a comment at the top explaining the expected flow of commands and why they are there would be helpful? |
d76062a to
8e6653e
Compare
|
Added some more comments. |
|
LGTM. BTW you don't mention it in the PR summary but |
|
@ijc25 I think that would require |
|
I think you are correct, it appeared to work for me because I tested it with a sha which was already present locally. If I try with one which is not present locally then it fails against GH at least: (that was trying to pull one of the parents of Seems that using vs but dropping the A bit odd. Anyway, you are correct that fetch by sha indeed doesn't work in the common case. |
dnephin
left a comment
There was a problem hiding this comment.
Some minor code changes, otherwise looks good
pkg/gitutils/gitutils.go
Outdated
There was a problem hiding this comment.
nit: probably more clear without the if, since it ends up being the same value in all cases anyway.
u.Fragment = ""
pkg/gitutils/gitutils.go
Outdated
There was a problem hiding this comment.
shallow is always true now, so this can be removed from the condition.
pkg/gitutils/gitutils.go
Outdated
There was a problem hiding this comment.
Looks like this is now duplicate with the code which calls this function.
8e6653e to
462fdf0
Compare
|
@dnephin Thanks! Updated PTAL |
462fdf0 to
ca2a4ea
Compare
|
Does this need an update to the documentation? https://github.com/moby/moby/blob/master/docs/reference/commandline/build.md#git-repositories |
Also changes so that shallow fetch is performed even when a specific ref is specified. Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
ca2a4ea to
493a6c3
Compare
|
@thaJeztah Updated docs. I removed the SHA examples because they don't really work in most cases. |
|
@thaJeztah ci errors unrelated |
|
After this PR, docker doesn't pull git repository recursively any more, is that the intended behavior? I think this is because |
|
@lgarithm Do you have suggestions for fixing this? Checking if |
|
@tonistiigi I think it should be OK to just run |
When specifying git URLs
git://repo#branchfor builder, fall back to any remote ref if branch or tag can't be found. For example build prs, usegit://repo#pull/NR/headedit: this pr used to be specifically for checking out PRs
Signed-off-by: Tonis Tiigi tonistiigi@gmail.com