upload-pack: advertise capabilities when cloning empty repos

When cloning an empty repository, protocol versions 0 and 1 currently
offer nothing but the header and flush packets for the /info/refs
endpoint. This means that no capabilities are provided, so the client
side doesn't know what capabilities are present.

However, this does pose a problem when working with SHA-256
repositories, since we use the capabilities to know the remote side's
object format (hash algorithm).  As of 8b214c2e9d ("clone: propagate
object-format when cloning from void", 2023-04-05), this has been fixed
for protocol v2, since there we always read the hash algorithm from the
remote.

Fortunately, the push version of the protocol already indicates a clue
for how to solve this.  When the /info/refs endpoint is accessed for a
push and the remote is empty, we include a dummy "capabilities^{}" ref
pointing to the all-zeros object ID.  The protocol documentation already
indicates this should _always_ be sent, even for fetches and clones, so
let's just do that, which means we'll properly announce the hash
algorithm as part of the capabilities.  This just works with the
existing code because we share the same ref code for fetches and clones,
and libgit2, JGit, and dulwich do as well.

There is one minor issue to fix, though.  If we called send_ref with
namespaces, we would return NULL with the capabilities entry, which
would cause a crash.  Instead, let's refactor out a function to print
just the ref itself without stripping the namespace and use it for our
special capabilities entry.

Add several sets of tests for HTTP as well as for local clones.  The
behavior can be slightly different for HTTP versus a local or SSH clone
because of the stateless-rpc functionality, so it's worth testing both.

Signed-off-by: brian m. carlson <bk2204@github.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
3 files changed
tree: 247e2666a7fd325910d8bee3b830a54195c9ff64
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. negotiator/
  14. oss-fuzz/
  15. perl/
  16. po/
  17. refs/
  18. reftable/
  19. sha1dc/
  20. sha256/
  21. t/
  22. templates/
  23. trace2/
  24. xdiff/
  25. .cirrus.yml
  26. .clang-format
  27. .editorconfig
  28. .gitattributes
  29. .gitignore
  30. .gitmodules
  31. .mailmap
  32. .tsan-suppressions
  33. abspath.c
  34. abspath.h
  35. aclocal.m4
  36. add-interactive.c
  37. add-interactive.h
  38. add-patch.c
  39. advice.c
  40. advice.h
  41. alias.c
  42. alias.h
  43. alloc.c
  44. alloc.h
  45. apply.c
  46. apply.h
  47. archive-tar.c
  48. archive-zip.c
  49. archive.c
  50. archive.h
  51. attr.c
  52. attr.h
  53. banned.h
  54. base85.c
  55. bisect.c
  56. bisect.h
  57. blame.c
  58. blame.h
  59. blob.c
  60. blob.h
  61. bloom.c
  62. bloom.h
  63. branch.c
  64. branch.h
  65. builtin.h
  66. bulk-checkin.c
  67. bulk-checkin.h
  68. bundle-uri.c
  69. bundle-uri.h
  70. bundle.c
  71. bundle.h
  72. cache-tree.c
  73. cache-tree.h
  74. cache.h
  75. cbtree.c
  76. cbtree.h
  77. chdir-notify.c
  78. chdir-notify.h
  79. check-builtins.sh
  80. checkout.c
  81. checkout.h
  82. chunk-format.c
  83. chunk-format.h
  84. CODE_OF_CONDUCT.md
  85. color.c
  86. color.h
  87. column.c
  88. column.h
  89. combine-diff.c
  90. command-list.txt
  91. commit-graph.c
  92. commit-graph.h
  93. commit-reach.c
  94. commit-reach.h
  95. commit-slab-decl.h
  96. commit-slab-impl.h
  97. commit-slab.h
  98. commit.c
  99. commit.h
  100. common-main.c
  101. config.c
  102. config.h
  103. config.mak.dev
  104. config.mak.in
  105. config.mak.uname
  106. configure.ac
  107. connect.c
  108. connect.h
  109. connected.c
  110. connected.h
  111. convert.c
  112. convert.h
  113. copy.c
  114. COPYING
  115. credential.c
  116. credential.h
  117. csum-file.c
  118. csum-file.h
  119. ctype.c
  120. daemon.c
  121. date.c
  122. date.h
  123. decorate.c
  124. decorate.h
  125. delta-islands.c
  126. delta-islands.h
  127. delta.h
  128. detect-compiler
  129. diagnose.c
  130. diagnose.h
  131. diff-delta.c
  132. diff-lib.c
  133. diff-merges.c
  134. diff-merges.h
  135. diff-no-index.c
  136. diff.c
  137. diff.h
  138. diffcore-break.c
  139. diffcore-delta.c
  140. diffcore-order.c
  141. diffcore-pickaxe.c
  142. diffcore-rename.c
  143. diffcore-rotate.c
  144. diffcore.h
  145. dir-iterator.c
  146. dir-iterator.h
  147. dir.c
  148. dir.h
  149. editor.c
  150. editor.h
  151. entry.c
  152. entry.h
  153. environment.c
  154. environment.h
  155. exec-cmd.c
  156. exec-cmd.h
  157. fetch-negotiator.c
  158. fetch-negotiator.h
  159. fetch-pack.c
  160. fetch-pack.h
  161. fmt-merge-msg.c
  162. fmt-merge-msg.h
  163. fsck.c
  164. fsck.h
  165. fsmonitor--daemon.h
  166. fsmonitor-ipc.c
  167. fsmonitor-ipc.h
  168. fsmonitor-path-utils.h
  169. fsmonitor-settings.c
  170. fsmonitor-settings.h
  171. fsmonitor.c
  172. fsmonitor.h
  173. generate-cmdlist.sh
  174. generate-configlist.sh
  175. generate-hooklist.sh
  176. gettext.c
  177. gettext.h
  178. git-archimport.perl
  179. git-compat-util.h
  180. git-curl-compat.h
  181. git-cvsexportcommit.perl
  182. git-cvsimport.perl
  183. git-cvsserver.perl
  184. git-difftool--helper.sh
  185. git-filter-branch.sh
  186. git-instaweb.sh
  187. git-merge-octopus.sh
  188. git-merge-one-file.sh
  189. git-merge-resolve.sh
  190. git-mergetool--lib.sh
  191. git-mergetool.sh
  192. git-p4.py
  193. git-quiltimport.sh
  194. git-request-pull.sh
  195. git-send-email.perl
  196. git-sh-i18n.sh
  197. git-sh-setup.sh
  198. git-submodule.sh
  199. git-svn.perl
  200. GIT-VERSION-GEN
  201. git-web--browse.sh
  202. git-zlib.c
  203. git-zlib.h
  204. git.c
  205. git.rc
  206. gpg-interface.c
  207. gpg-interface.h
  208. graph.c
  209. graph.h
  210. grep.c
  211. grep.h
  212. hash-lookup.c
  213. hash-lookup.h
  214. hash.h
  215. hashmap.c
  216. hashmap.h
  217. help.c
  218. help.h
  219. hex.c
  220. hex.h
  221. hook.c
  222. hook.h
  223. http-backend.c
  224. http-fetch.c
  225. http-push.c
  226. http-walker.c
  227. http.c
  228. http.h
  229. ident.c
  230. ident.h
  231. imap-send.c
  232. INSTALL
  233. iterator.h
  234. json-writer.c
  235. json-writer.h
  236. khash.h
  237. kwset.c
  238. kwset.h
  239. levenshtein.c
  240. levenshtein.h
  241. LGPL-2.1
  242. line-log.c
  243. line-log.h
  244. line-range.c
  245. line-range.h
  246. linear-assignment.c
  247. linear-assignment.h
  248. list-objects-filter-options.c
  249. list-objects-filter-options.h
  250. list-objects-filter.c
  251. list-objects-filter.h
  252. list-objects.c
  253. list-objects.h
  254. list.h
  255. ll-merge.c
  256. ll-merge.h
  257. lockfile.c
  258. lockfile.h
  259. log-tree.c
  260. log-tree.h
  261. ls-refs.c
  262. ls-refs.h
  263. mailinfo.c
  264. mailinfo.h
  265. mailmap.c
  266. mailmap.h
  267. Makefile
  268. match-trees.c
  269. mem-pool.c
  270. mem-pool.h
  271. merge-blobs.c
  272. merge-blobs.h
  273. merge-ort-wrappers.c
  274. merge-ort-wrappers.h
  275. merge-ort.c
  276. merge-ort.h
  277. merge-recursive.c
  278. merge-recursive.h
  279. merge.c
  280. mergesort.h
  281. midx.c
  282. midx.h
  283. name-hash.c
  284. notes-cache.c
  285. notes-cache.h
  286. notes-merge.c
  287. notes-merge.h
  288. notes-utils.c
  289. notes-utils.h
  290. notes.c
  291. notes.h
  292. object-file.c
  293. object-file.h
  294. object-name.c
  295. object-name.h
  296. object-store.h
  297. object.c
  298. object.h
  299. oid-array.c
  300. oid-array.h
  301. oidmap.c
  302. oidmap.h
  303. oidset.c
  304. oidset.h
  305. oidtree.c
  306. oidtree.h
  307. pack-bitmap-write.c
  308. pack-bitmap.c
  309. pack-bitmap.h
  310. pack-check.c
  311. pack-mtimes.c
  312. pack-mtimes.h
  313. pack-objects.c
  314. pack-objects.h
  315. pack-revindex.c
  316. pack-revindex.h
  317. pack-write.c
  318. pack.h
  319. packfile.c
  320. packfile.h
  321. pager.c
  322. pager.h
  323. parallel-checkout.c
  324. parallel-checkout.h
  325. parse-options-cb.c
  326. parse-options.c
  327. parse-options.h
  328. patch-delta.c
  329. patch-ids.c
  330. patch-ids.h
  331. path.c
  332. path.h
  333. pathspec.c
  334. pathspec.h
  335. pkt-line.c
  336. pkt-line.h
  337. preload-index.c
  338. pretty.c
  339. pretty.h
  340. prio-queue.c
  341. prio-queue.h
  342. progress.c
  343. progress.h
  344. promisor-remote.c
  345. promisor-remote.h
  346. prompt.c
  347. prompt.h
  348. protocol-caps.c
  349. protocol-caps.h
  350. protocol.c
  351. protocol.h
  352. prune-packed.c
  353. prune-packed.h
  354. quote.c
  355. quote.h
  356. range-diff.c
  357. range-diff.h
  358. reachable.c
  359. reachable.h
  360. read-cache.c
  361. README.md
  362. rebase-interactive.c
  363. rebase-interactive.h
  364. rebase.c
  365. rebase.h
  366. ref-filter.c
  367. ref-filter.h
  368. reflog-walk.c
  369. reflog-walk.h
  370. reflog.c
  371. reflog.h
  372. refs.c
  373. refs.h
  374. refspec.c
  375. refspec.h
  376. remote-curl.c
  377. remote.c
  378. remote.h
  379. replace-object.c
  380. replace-object.h
  381. repo-settings.c
  382. repository.c
  383. repository.h
  384. rerere.c
  385. rerere.h
  386. reset.c
  387. reset.h
  388. resolve-undo.c
  389. resolve-undo.h
  390. revision.c
  391. revision.h
  392. run-command.c
  393. run-command.h
  394. scalar.c
  395. SECURITY.md
  396. send-pack.c
  397. send-pack.h
  398. sequencer.c
  399. sequencer.h
  400. serve.c
  401. serve.h
  402. server-info.c
  403. setup.c
  404. setup.h
  405. sh-i18n--envsubst.c
  406. sha1dc_git.c
  407. sha1dc_git.h
  408. shallow.c
  409. shallow.h
  410. shared.mak
  411. shell.c
  412. shortlog.h
  413. sideband.c
  414. sideband.h
  415. sigchain.c
  416. sigchain.h
  417. simple-ipc.h
  418. sparse-index.c
  419. sparse-index.h
  420. split-index.c
  421. split-index.h
  422. stable-qsort.c
  423. statinfo.h
  424. strbuf.c
  425. strbuf.h
  426. streaming.c
  427. streaming.h
  428. string-list.c
  429. string-list.h
  430. strmap.c
  431. strmap.h
  432. strvec.c
  433. strvec.h
  434. sub-process.c
  435. sub-process.h
  436. submodule-config.c
  437. submodule-config.h
  438. submodule.c
  439. submodule.h
  440. symlinks.c
  441. tag.c
  442. tag.h
  443. tar.h
  444. tempfile.c
  445. tempfile.h
  446. thread-utils.c
  447. thread-utils.h
  448. tmp-objdir.c
  449. tmp-objdir.h
  450. trace.c
  451. trace.h
  452. trace2.c
  453. trace2.h
  454. trailer.c
  455. trailer.h
  456. transport-helper.c
  457. transport-internal.h
  458. transport.c
  459. transport.h
  460. tree-diff.c
  461. tree-walk.c
  462. tree-walk.h
  463. tree.c
  464. tree.h
  465. unicode-width.h
  466. unimplemented.sh
  467. unix-socket.c
  468. unix-socket.h
  469. unix-stream-server.c
  470. unix-stream-server.h
  471. unpack-trees.c
  472. unpack-trees.h
  473. upload-pack.c
  474. upload-pack.h
  475. url.c
  476. url.h
  477. urlmatch.c
  478. urlmatch.h
  479. usage.c
  480. userdiff.c
  481. userdiff.h
  482. utf8.c
  483. utf8.h
  484. varint.c
  485. varint.h
  486. version.c
  487. version.h
  488. versioncmp.c
  489. walker.c
  490. walker.h
  491. wildmatch.c
  492. wildmatch.h
  493. worktree.c
  494. worktree.h
  495. wrap-for-bin.sh
  496. wrapper.c
  497. wrapper.h
  498. write-or-die.c
  499. write-or-die.h
  500. ws.c
  501. wt-status.c
  502. wt-status.h
  503. xdiff-interface.c
  504. xdiff-interface.h
README.md

Build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-<commandname>.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org (not the Git list). The mailing list archives are available at https://lore.kernel.org/git/, http://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks