git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fetch-pack: always allow fetching of literal SHA1s

From
Shawn Pearce <spearce@spearce.org>
Date
May 10, 2017, 04:22 UTC
Message-ID
<CAJo=hJvAg2WqpiuykpbHcB5vgQiHJ74CZ8Y4qudkYqZrmd30zg@mail.gmail.com>
In-Reply-To
<20170509221629.3z35qcz36oiix3kh@sigill.intra.peff.net>
On Tue, May 9, 2017 at 3:16 PM, Jeff King <peff@peff.net> wrote:
Show 16 quoted lines
> On Tue, May 09, 2017 at 11:20:42AM -0700, Jonathan Tan wrote:
>
>> fetch-pack, when fetching a literal SHA-1 from a server that is not
>> configured with uploadpack.allowtipsha1inwant (or similar), always
>> returns an error message of the form "Server does not allow request for
>> unadvertised object %s". However, it is sometimes the case that such
>> object is advertised.
>>
>> Teach fetch-pack to also check the SHA-1s of the refs in the received
>> ref advertisement if a literal SHA-1 was given by the user.
>
> Hmm. That makes sense generally, as the request should succeed. But it
> seems like we're creating a client that will sometimes succeed and
> sometimes fail, and the reasoning will be somewhat opaque to the user.
> I have a feeling I'm missing some context on when you'd expect this to
> kick in.

Specifically, someone I know was looking at building an application that is passed only a SHA-1 for the tip of a ref on a popular hosting site[1]. They wanted to run `git fetch URL SHA1`, but this failed because the site doesn't have upload.allowtipsha1inwant enabled. However the SHA1 was clearly in the output of git ls-remote.

So a workaround is to do this in shell, which is just weird:
  r=$(git ls-remote $url | grep ^$sha1);
  if [ -n "$r" ]; then
    exec git fetch $url $r:refs/tmp/foo
  else
    echo >&2 "cannot find $sha1"
    exit 1
  fi

For various reasons they expected this to work, because it works against other sites that do have upload.allowtipsha1inwant enabled. And I personally just expected it to work because the fetch client accepts SHA-1s, and the wire protocol uses "want SHA1" not "want ref", and the SHA-1 passed on the command line was currently in the advertisement when the connection opened, so its certainly something the server is currently willing to serve.

The application in question is using a SHA-1 rather than a ref name, because thats what it was given by something else. And the other thing basically wants this to fail-fast if it can't get that exact SHA-1. So to pass a ref name to git fetch the supplier would have to actually pass a tuple of ref+sha1, and then the fetcher has to check that the ref it just obtained provides the sha1 it expected.

So this all turned into a bug report by me to Jonathan Tan, because git fetch violated my assumption of what it would do if I handed it a SHA-1 and the SHA-1 was currently the tip of a remote ref.

[1] github.com
Previous: Jeff KingNext: Jeff King
Message 3 of 47 in “fetch-pack: always allow fetching of literal SHA1s”
  1. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 9, 2017
  2. Jeff KingMay 9, 2017
  3. Shawn PearceMay 10, 2017
  4. Jeff KingMay 10, 2017
  5. Shawn PearceMay 10, 2017
  6. Mike HommeyMay 10, 2017
  7. Ævar Arnfjörð BjarmasonMay 10, 2017
  8. Jonathan NiederMay 10, 2017
  9. Martin FickMay 10, 2017
  10. Jonathan NiederMay 10, 2017
  11. Jonathan NiederMay 10, 2017
  12. Sebastian SchuberthMay 10, 2017
  13. Jeff KingMay 11, 2017
  14. Jonathan NiederMay 11, 2017
  15. Jeff KingMay 11, 2017
  16. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 10, 2017
  17. Jonathan NiederMay 10, 2017
  18. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 10, 2017
  19. Jonathan NiederMay 10, 2017
  20. Jeff KingMay 11, 2017
  21. Jonathan TanMay 11, 2017
  22. Jeff KingMay 11, 2017
  23. Jeff KingMay 11, 2017
  24. Brandon WilliamsMay 11, 2017
  25. Jeff KingMay 13, 2017
  26. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 11, 2017
  27. Jonathan NiederMay 11, 2017
  28. Jeff KingMay 11, 2017
  29. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 11, 2017
  30. Jonathan NiederMay 11, 2017
  31. Jeff KingMay 12, 2017
  32. Junio C HamanoMay 12, 2017
  33. Jeff KingMay 12, 2017
  34. Jonathan TanMay 12, 2017
  35. Jonathan NiederMay 12, 2017
  36. Jeff KingMay 12, 2017
  37. Jonathan TanMay 12, 2017
  38. Jeff KingMay 13, 2017
  39. Jeff KingMay 12, 2017
  40. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 12, 2017
  41. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 12, 2017
  42. Jonathan NiederMay 12, 2017
  43. Jeff KingMay 13, 2017
  44. Junio C HamanoMay 15, 2017
  45. fetch-pack: always allow fetching of literal SHA1sJonathan Tan, May 15, 2017
  46. Jonathan NiederMay 15, 2017
  47. Jeff KingMay 15, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.