3

Some Git servers or hosting services (apparently GitHub Enterprise) are not supporting shallow clones, instead they simply stall when a request like the following is sent:

git clone --depth 1 https://server/user/repo.git

Is there a way to detect whether the server supports shallow cloning or not? Is there a Git or CURL command that I can send to the server to find out whether it supports shallow cloning or not?

I've found a reference to Git Protocol Capabilities, is this what I need to look for? How can I get a hold of the server's capabilities?

nwinkler
  • 52,665
  • 21
  • 154
  • 168

1 Answers1

3

The smart protocol does some advertisement

ssh -x git@server "git-receive-pack 'simplegit-progit.git'"
005bca82a6dff817ec66f4437202690a93763949 refs/heads/master report-status \
    delete-refs side-band-64k quiet ofs-delta \
    agent=git/2:2.1.1+github-607-gfba4028 delete-refs

The git-receive-pack command immediately responds with one line for each reference it currently has – in this case, just the master branch and its SHA-1.
The first line also has a list of the server’s capabilities (here, report-status, delete-refs, and some others, including the client identifier).

The git remote helpers have options related to the shallow capability, but it is not clear they would be advertised the same way as in the ssh command above.

git 1.6.6 updated the packfile transfer protocol, including a "Reference Discovery" section:

When the client initially connects the server will immediately respond with a listing of each reference it has (all branches and tags) along with the object name that each reference currently points to.

$ echo -e -n "0039git-upload-pack /schacon/gitbook.git\0host=example.com\0" |
nc -v example.com 9418
00887217a7c7e582c46cec22a130adf4b9d7d950fba0 HEAD\0multi_ack thin-pack
side-band side-band-64k ofs-delta shallow no-progress include-tag
00441d3fcd5ced445d1abc402225c0b8a1299641f497 refs/heads/integration
003f7217a7c7e582c46cec22a130adf4b9d7d950fba0 refs/heads/master
003cb88d2441cac0977faf98efc80305012112238d9d refs/tags/v0.9
003c525128480b96c89e6418b1e40909bf6c5b2d580f refs/tags/v1.0
003fe92df48743b7bc7d26bcaabfddde0a1e20cae47c refs/tags/v1.0^{}
0000

These days (Git 2.23, Q3 2019, 4 years later), a git fetch -v -v would be enough to show any supported capabilities.

See commit 0e04297, commit 5a88583, commit 0778b29 (20 Jun 2019) by Nguyễn Thái Ngọc Duy (pclouds).
(Merged by Junio C Hamano -- gitster -- in commit b49d337, 09 Jul 2019)

fetch-pack: print server version at the top in -v -v

Before the previous patch, the server version is printed after all the "Server supports" lines.
The previous one puts the version in the middle of "Server supports" group.

Instead of moving it to the bottom, I move it to the top.
Version may stand out more at the top as we will have even more debug out after capabilities.

fetch-pack: print all relevant supported capabilities with -v -v

When we check if some capability is supported, we do print something in verbose mode.
Some capabilities are not printed though (and it made me think it's not supported; I was more used to GIT_TRACE_PACKET) so let's print them all.

It's a bit more code. And one could argue for printing all supported capabilities the server sends us. But I think it's still valuable this way because we see the capabilities that the client cares about.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've read a lot about the smart protocol, but I'm not sure this helps. I've tried to run the SSH `git-receive-pack` command against GitHub (not Enterprise), and it doesn't send back the `shallow` capability, yet GitHub supports shallow cloning without any problems. – nwinkler Apr 02 '15 at 07:36
  • I agree. I just meant to give some clues, to start looking where and how shallow clone is managed on the server side. – VonC Apr 02 '15 at 07:41
  • Thanks - this seems to be a rather complex topic, and I'm completely stumped why GitHub Enterprise doesn't seem to support this cleanly. – nwinkler Apr 02 '15 at 07:43
  • As seen in your other question today, you have a lot of questions to ask to github support ;) – VonC Apr 02 '15 at 07:45
  • Indeed - it's a real nightmare :-) – nwinkler Apr 02 '15 at 07:46