-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tags): do not peel tag when cloning #1442
Conversation
I have no idea if this correct @mojavelinux Do you know if this change should be added to the library. The tests are passing, so it should be right. |
I have tests in Antora that would be able to give me insight into what impact this has and whether it's doing the right thing (as I'm sure it is...but it's always good to test). I'll try to look at it this week. I vaguely remember having to workaround the lack of tag peeling...but it's been awhile so I need to refresh my memory. |
I can confirm that this is the correct behavior. If I clone the repository without this patch, I see the following tag for the repository I cloned when I run
However, that's not correct. That's showing a lightweight tag. It should be an annotated tag. If I apply this patch, reclone, then run
That's consistent with the result when cloning with the git command. What concerns me about this patch is that there is no test. I would like to see a test that verifies that the annotate tag is preserved during a clone. |
I'll see what I can do. Not super familiar with the codebase but would be awesome if I could get a test in. |
Excellent. Usually, I try to see if I can find a test which is close, perhaps one already doing the work, then just build on that. If you need help, don't hesitate to ask. |
So I tried setting up a test, but it's a pain. Or maybe, there's another way of doing it. So I looked at the const { fs, dir, gitdir } = await makeFixture('isomorphic-git')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
singleBranch: true,
ref: 'v0.0.10',
url: 'https://github.com/isomorphic-git/isomorphic-git.git',
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
})
const oid = await fs._readFile(`${gitdir}/refs/tags/v0.0.10`, 'utf8')
expect(oid.trim()).toBe('0a117b8378f5e5323d15694c7eb8f62c4bea152b') This doesn't fail because it only checks out the tag So for it to test correctly, I should have to clone the entire const { fs, dir, gitdir } = await makeFixture('isomorphic-git')
await clone({
fs,
http,
dir,
gitdir,
url: 'https://github.com/isomorphic-git/isomorphic-git.git',
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
})
const oid = await fs._readFile(`${gitdir}/refs/tags/v0.0.10`, 'utf8')
expect(oid.trim()).toBe('0a117b8378f5e5323d15694c7eb8f62c4bea152b') So not entirely sure how to proceed from here. Any ideas? |
There are two approaches you could take. First clone a smaller repository, such as https://github.com/isomorphic-git/lightning-fs. But better would be to keep the test self contained. The test suite has a git server in it. You can use that to serve a repository you use isomorphic-git to create, then check the clone behavior. See https://github.com/isomorphic-git/isomorphic-git/blob/main/__tests__/test-clone.js#L117-L138 ...though I wonder why you couldn't just add an assertion to this test: https://github.com/isomorphic-git/isomorphic-git/blob/main/__tests__/test-clone.js#L71-L92 |
It's the same thing. It specifically checks out that tag, which means that I think it would be a good idea to use that mock github server to give me something back that I want. |
What you're saying here is not consistent with the output I showed above using |
You are correct, it does peel the tag. But the behaviour is different if you change the input parameters. If you use
But what we want here is to verify that that specific tag is not peeled without cloning the entire repository. So passing
Which is the annotated object id, and not the peeled one. This behaviour is different if you clone the entire repo.
The reason for this behaviour is that if you pass in the The reason is probably due to the fact it takes a different code path when fetching a repository when only cloning a single branch. Because if we only clone a single branch, it will not use the I hope this makes a bit of sense? I might be missing some bits and pieces because as said before, not super familiair with the codebase. |
Thank you for sharing the analysis. That does make sense to me. What I'm not sure about is how this relates to the request to write a test. If the code is being changed, it must be possible to assert that there a behavior change in the output under that condition. What I showed above was the output before and after applying this patch. All I'm requesting is that there's a test that verifies that isomorphic-git no longer peels the tag in that scenario. Then we can move forward. |
Yes, and this is what I'm trying to do. But in order to verify this behavior change I need to clone an entire repo with all it's tags and what not. So as you suggested, I'm looking into writing a self-contained test or cloning a smaller repo. I looked at |
Got it. 👍
In Antora, I use node-git-server, which works extremely well. Instead of messing with making a mock, it's a real git server. Here's how I use it: https://gitlab.com/antora/antora/-/blob/main/packages/cli/test/cli-test.js#L71-77 |
Ironically, the test.empty repository is not actually empty. Since this test isn't really about the behavior of a repository service like GitHub or GitLab, I think it's best to keep it self-contained. |
I now realize you were referring to cloning the repository, not using it. Still, I think having to use a remote repository is really unnecessary on the whole. I think most of isomorphic-git tests should be self-contained...only using GitHub when the intent is to very exchange with GitHub specifically. |
But for the purpose of this MR, I think it's fine to use the git-http-mock-server repository as a fixture. |
I was able to add a self-contained test based on |
Great work! |
Thanks for great work. |
🎉 This PR is included in version 1.10.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Awesome! Thanks for helping me out and for the feedback 🙏 ! Highly appreciated. |
* fix(tags): do not peel tag when cloning * chore: add tests
I'm fixing a bug or typo
npm run add-contributor
and follow the prompts to add yourself to the READMEThis PR fixes #1441. I think a tag should always use the serverref, and not the peeled object id instead as explained in the original issue.