-
Notifications
You must be signed in to change notification settings - Fork 1k
Don't assume every git repository has a HEAD #1053
Conversation
hmm, interesting. could you explain the circumstances under which a git repo might lack a HEAD? the one case I can imagine is cloning an empty repo. the empty repo case also makes me think...there is currently an undocumented assumption that ListVersions will return at least one item. when that assumption isn't met, the solver has a panic condition. we've run into that panic before with gopkg.in, but I have, until now, thought that assumption was still an accurate one. this is making me think that, though - and besides, even if it's an accurate assumption, it's still not a good one, as solver code is not resilient against a particular output that's valid with respect to type signatures. I'll look at this more in depth next week, when I'm back from vacation and not sitting in an oil change shop lobby. |
In my case, the remote repository did have a Steps to reproduce:
With this PR and the situation above, My code hosting platform (Phabricator) has no way of changing the |
ahhhh, yes, that case also makes sense. (i actually created a similar problem to what Phabricator imposes in a git hosting platform i built, now that i think about it 😢). so yeah, we'll need to adapt the solver to really do this properly. the same basic issue there is #776. |
I'm don't think that the issue in #776 (with dep version v0.1.0-175-gc79b048) still occurs in the version I based my PR on (v0.3.0-151-g1f6d6bb). With the patch from my PR applied (which only fixes a panic/out of bounds access inside of Do you agree this PR fixes a problem on its own, and that the case where |
mm, i suppose that's fair. still, we need some test cases to cover this. that may be a bit awkward - probably the easiest thing to do would be to create a git repository on the fly, munge it so that there is no HEAD, and work from there. note: there are some helpers for working with git in |
I'm not sure I know how to write a test like that; I'm new to Go (and dep) and the other tests in Do you have a suggestion on how to advance this PR? |
@Minnozz you can start writing the test referring to Test_hgSource_exportRevisionTo_removeVcsFiles, which uses some of our test helpers. Since we need to create a git repo on the fly in this case, you can create a tempdir using the test helper and then run git commands in the tempdir using RunGit(). Once the repo is in the desired state (without HEAD), you can create a You can use I don't think this would require any fixture data, but in case you need them, you can create Let us know if you need any help :) |
@darkowlzz Thanks a lot for the instructions. I gave it a try, let me know what you think. I'm not sure what qualifies as a slow test. I think this one does not, since there is no network communication. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!! 🎉
I tried and it seems to work. No more panics and fetches proper version list.
But the test seems to be failing on Windows https://ci.appveyor.com/project/golang/dep/build/1967 .
My guess is, it's because of file:///
. Not sure. @carolynvs any idea about this?
Suggested small changes.
internal/gps/vcs_source_test.go
Outdated
@@ -524,6 +524,62 @@ func testHgSourceInteractions(t *testing.T) { | |||
<-donech | |||
} | |||
|
|||
func Test_gitSource_listVersions_noHEAD(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we decided to not do any more snake case function names, idiomatic go. The ones that you see are old code, we need to change them. So, let's rename this to TestGitSourceListVersionsNoHEAD
.
internal/gps/vcs_source_test.go
Outdated
un := "file://" + repoPath | ||
u, err := url.Parse(un) | ||
if err != nil { | ||
t.Errorf("URL was bad, lolwut? errtext: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOL! 😄
Let's make this Fatalf
.
t.Fatalf("Error parsing URL %s: %s", un, err)
internal/gps/vcs_source_test.go
Outdated
} | ||
|
||
if len(pvlist) != 1 { | ||
t.Errorf("expected 1 version pair from listVersions(), got %d", len(pvlist)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to GOT/WNT style message:
t.Errorf("Unexpected version pair length:\n\t(GOT): %d\n\t(WNT): %d", len(pvlist), 1)
No, it's fine. This need not be a slow test. Yeah, network or tests that run for long need this. This one doesn't take any time. |
@ibrasho ping! Maybe you too can help with windows related issues? 😊 |
Most likely this error is because |
For the record, this patch also fixes #1112 Is there anything I can do to help with this PR to make it good for integration in master ? |
@mremond I intend to address the suggested changes from @darkowlzz today or tomorrow. After that, we'll have to see if the tests pass on Windows. @ibrasho I will try adding |
Another option is adding the pre-prepared repository (without |
@Minnozz I'm just trying to figure out if that's the actual reason. If it's, we can decide what's the appropriate long-term solution then. 😄 |
Fixes an error when the git user is not set.
Adding Having the output of the failing git command would be very useful; running the tests wit |
I fixed the test on Windows: https://ci.appveyor.com/project/golang/dep/build/2015 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for fixing this. 👍 |
What does this do / why do we need it?
The code that determines the versions of a git repository assumes that all git repositories have a
HEAD
. It panics when this is not the case.What should your reviewer look out for in this PR?
Not sure if the big comment block above the changes should be edited.
Do you need help or clarification on anything?
Is using the zero value of
Revision
like this okay?Which issue(s) does this PR fix?
Fixes #1051, Fixes #1112