Skip to content
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: empty git-upload-pack given on remote.fetch() #447

Closed
wants to merge 5 commits into from

Conversation

greenpau
Copy link

More info: This change prevents an attempt to upload pack
when UploadPackRequest is empty.

Partial Resolution: #328

Signed-off-by: Paul Greenberg greenpau@outlook.com

More info: This change prevents an attempt to upload pack
when UploadPackRequest is empty.

Partial Resolution: go-git#328

Signed-off-by: Paul Greenberg <greenpau@outlook.com>
@mcuadros
Copy link
Member

can you cover it with some test?

@greenpau
Copy link
Author

can you cover it with some test?

@mcuadros , will do! 👍 will also need to do some adjustments to the code.

@greenpau
Copy link
Author

@mcuadros , moved the check to the UploadPack function. The was introduced to ./plumbing/transport/internal/common/common.go in #311.

Here, I add the same to the UploadPack functions in the following files.

  • ./plumbing/transport/http/upload_pack.go
  • ./plumbing/transport/file/server.go

Created TestFetchShallows test, where provided depth 0.

Receiving the following error in the unrelated repository_test.go.

FAIL: repository_test.go:640: RepositorySuite.TestPlainOpenNotExistsDetectDotGit

repository_test.go:646:
    c.Assert(err, Equals, ErrRepositoryNotExists)
... obtained = nil
... expected *errors.errorString = &errors.errorString{s:"repository does not exist"} ("repository does not exist")

I am not 💯 sure about the TestFetchShallows. Please take a look and let me know what to adjust in the test. Many thanks!

@magnusbaeck
Copy link

magnusbaeck commented Jan 21, 2022

This patch doesn't help in my situation, which perhaps isn't surprising since I'm not making a shallow fetch. What's puzzling to me is that the wanted SHA-1 in wants really exists in the haves list so it's clear why isEmpty returns true. But shouldn't a commit in haves be available in the git, i.e. a checkout or git show operation would succeed? If I comment out the conditional in upload_pack.go that returns ErrEmptyUploadPackRequest I get an empty packfile and a ref that points to a non-existent object.

I apologize if you think I'm derailing your PR, maybe my problem is something entirely different (mysterious problems are often a case of PEBKAC), but it might also hint at a different root cause whereas the current state of this PR only addresses a particular corner case. Either way, I'd be happy to help debug the problem.

@greenpau
Copy link
Author

I apologize if you think I'm derailing your PR, maybe my problem is something entirely different (mysterious problems are often a case of PEBKAC), but it might also hint at a different root cause whereas the current state of this PR only addresses a particular corner case. Either way, I'd be happy to help debug the problem.

@magnusbaeck , this is valuable discussion! 👍 Please challenge, propose something new, etc.

@magnusbaeck
Copy link

The reason my wanted SHA-1 ended up in haves was that HEAD contained that SHA-1. My code looks like this:

	err = worktree.Checkout(&git.CheckoutOptions{
		Hash:  plumbing.NewHash(commitID),
		Force: true,
	})
	if errors.Is(err, plumbing.ErrObjectNotFound) {
		refSpec := fmt.Sprintf("+%s:tmp", ref)
		err = gr.git.FetchContext(ctx, &git.FetchOptions{
			RefSpecs: []gitconfig.RefSpec{gitconfig.RefSpec(refSpec)},
			Tags:     git.NoTags,
		})
		...

It seems the failing checkout operation still ends up storing the wanted SHA-1 in HEAD, so when the subsequent fetch operation computes the haves set it picks up the SHA-1 from HEAD, resulting in an empty (wants − haves) set and hence ErrEmptyUploadPackRequest.

I'll double check to make sure the SHA-1 didn't end up in HEAD by other means, but if my analysis is correct I'll file an issue for the checkout behavior unless there already is one.

@magnusbaeck
Copy link

I'll double check to make sure the SHA-1 didn't end up in HEAD by other means, but if my analysis is correct I'll file an issue for the checkout behavior unless there already is one.

For posterity my unrelated problem was filed as #457.

jspdown added a commit to traefik/go-git that referenced this pull request Jul 1, 2022
})

s.testFetch(c, r, &FetchOptions{
Depth: 0,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test it with non-zero value?

@l0nax
Copy link

l0nax commented May 5, 2023

@greenpau @mcuadros Is there any reason this PR cannot be merged?

@greenpau
Copy link
Author

greenpau commented May 8, 2023

Is there any reason this PR cannot be merged?

@l0nax , I cannot merge that. Not a maintainer of this package.

1 similar comment
@greenpau
Copy link
Author

greenpau commented May 8, 2023

Is there any reason this PR cannot be merged?

@l0nax , I cannot merge that. Not a maintainer of this package.

@pjbgf
Copy link
Member

pjbgf commented May 20, 2023

@greenpau do you mind rebasing your PR and also adding a test case to validate non-zero values for Depth?

@greenpau
Copy link
Author

@pjbgf , I rebased. Unfortunately, it has been a while since I looked into this code. Could you add a test yourself?

@AriehSchneier
Copy link
Contributor

This can be closed as it was fixed in #792

@pjbgf pjbgf closed this Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants