mergetool(vimdiff): allow paths to contain spaces again

In 0041797449d (vimdiff: new implementation with layout support,
2022-03-30), we introduced a completely new implementation of the
`vimdiff` backend for `git mergetool`.

In this implementation, we no longer call `vim` directly but we
accumulate in the variable `FINAL_CMD` an arbitrary number of commands
for `vim` to execute, which necessitates the use of `eval` to split the
commands properly into multiple command-line arguments.

That same `eval` command also needs to pass the paths to `vim`, and
while it looks as if they are quoted correctly, that quoting only
reaches the `eval` instruction and is lost after that, therefore paths
that contain whitespace characters (or other characters that are
interpreted by the POSIX shell) are handled incorrectly.

This is a simple reproducer:

	git init -b main bam-merge-fail
	cd bam-merge-fail
	echo a>"a file.txt"
	git add "a file.txt"
	git commit -m "added 'a file.txt'"
	echo b>"a file.txt"
	git add "a file.txt"
	git commit -m "diverged b 'a file.txt'"
	git checkout -b c HEAD~
	echo c>"a file.txt"
	git add "a file.txt"
	git commit -m "diverged c 'a file.txt'"
	git checkout main
	git merge c
	git mergetool --tool=vimdiff

With Git v2.37.0/v2.37.1, this will open 7 buffers, not four, and not
display the correct contents at all.

To fix this, let's not expand the variables containing the path
parameters before passing them to the `eval` command, but let that
command expand the variables instead.

This fixes https://github.com/git-for-windows/git/issues/3945

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