git_connect(): fix corner cases in downgrading v2 to v0

There's code in git_connect() that checks whether we are doing a push
with protocol_v2, and if so, drops us to protocol_v0 (since we know
how to do v2 only for fetches). But it misses some corner cases:

  1. it checks the "prog" variable, which is actually the path to
     receive-pack on the remote side. By default this is just
     "git-receive-pack", but it could be an arbitrary string (like
     "/path/to/git receive-pack", etc). We'd accidentally stay in v2
     mode in this case.

  2. besides "receive-pack" and "upload-pack", there's one other value
     we'd expect: "upload-archive" for handling "git archive --remote".
     Like receive-pack, this doesn't understand v2, and should use the
     v0 protocol.

In practice, neither of these causes bugs in the real world so far. We
do send a "we understand v2" probe to the server, but since no server
implements v2 for anything but upload-pack, it's simply ignored. But
this would eventually become a problem if we do implement v2 for those
endpoints, as older clients would falsely claim to understand it,
leading to a server response they can't parse.

We can fix (1) by passing in both the program path and the "name" of the
operation. I treat the name as a string here, because that's the pattern
set in transport_connect(), which is one of our callers (we were simply
throwing away the "name" value there before).

We can fix (2) by allowing only known-v2 protocols ("upload-pack"),
rather than blocking unknown ones ("receive-pack" and "upload-archive").
That will mean whoever eventually implements v2 push will have to adjust
this list, but that's reasonable. We'll do the safe, conservative thing
(sticking to v0) by default, and anybody working on v2 will quickly
realize this spot needs to be updated.

The new tests cover the receive-pack and upload-archive cases above, and
re-confirm that we allow v2 with an arbitrary "--upload-pack" path (that
already worked before this patch, of course, but it would be an easy
thing to break if we flipped the allow/block logic without also handling
"name" separately).

Here are a few miscellaneous implementation notes, since I had to do a
little head-scratching to understand who calls what:

  - transport_connect() is called only for git-upload-archive. For
    non-http git remotes, that resolves to the virtual connect_git()
    function (which then calls git_connect(); confused yet?). So
    plumbing through "name" in connect_git() covers that.

  - for regular fetches and pushes, callers use higher-level functions
    like transport_fetch_refs(). For non-http git remotes, that means
    calling git_connect() under the hood via connect_setup(). And that
    uses the "for_push" flag to decide which name to use.

  - likewise, plumbing like fetch-pack and send-pack may call
    git_connect() directly; they each know which name to use.

  - for remote helpers (including http), we already have separate
    parameters for "name" and "exec" (another name for "prog"). In
    process_connect_service(), we feed the "name" to the helper via
    "connect" or "stateless-connect" directives.

    There's also a "servpath" option, which can be used to tell the
    helper about the "exec" path. But no helpers we implement support
    it! For http it would be useless anyway (no reasonable server
    implementation will allow you to send a shell command to run the
    server). In theory it would be useful for more obscure helpers like
    remote-ext, but even there it is not implemented.

    It's tempting to get rid of it simply to reduce confusion, but we
    have publicly documented it since it was added in fa8c097cc9
    (Support remote helpers implementing smart transports, 2009-12-09),
    so it's possible some helper in the wild is using it.

  - So for v2, helpers (again, including http) are mainly used via
    stateless-connect, driven by the main program. But they do still
    need to decide whether to do a v2 probe. And so there's similar
    logic in remote-curl.c's discover_refs() that looks for
    "git-receive-pack". But it's not buggy in the same way. Since it
    doesn't support servpath, it is always dealing with a "service"
    string like "git-receive-pack". And since it doesn't support
    straight "connect", it can't be used for "upload-archive".

    So we could leave that spot alone. But I've updated it here to match
    the logic we're changing in connect_git(). That seems like the least
    confusing thing for somebody who has to touch both of these spots
    later (say, to add v2 push support). I didn't add a new test to make
    sure this doesn't break anything; we already have several tests (in
    t5551 and elsewhere) that make sure we are using v2 over http.

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