mingw: special-case arguments to `sh`

The MSYS2 runtime does its best to emulate the command-line wildcard
expansion and de-quoting which would be performed by the calling Unix
shell on Unix systems.

Those Unix shell quoting rules differ from the quoting rules applying to
Windows' cmd and Powershell, making it a little awkward to quote
command-line parameters properly when spawning other processes.

In particular, git.exe passes arguments to subprocesses that are *not*
intended to be interpreted as wildcards, and if they contain
backslashes, those are not to be interpreted as escape characters, e.g.
when passing Windows paths.

Note: this is only a problem when calling MSYS2 executables, not when
calling MINGW executables such as git.exe. However, we do call MSYS2
executables frequently, most notably when setting the use_shell flag in
the child_process structure.

There is no elegant way to determine whether the .exe file to be
executed is an MSYS2 program or a MINGW one. But since the use case of
passing a command line through the shell is so prevalent, we need to
work around this issue at least when executing sh.exe.

Let's introduce an ugly, hard-coded test whether argv[0] is "sh", and
whether it refers to the MSYS2 Bash, to determine whether we need to
quote the arguments differently than usual.

That still does not fix the issue completely, but at least it is
something.

Incidentally, this also fixes the problem where `git clone \\server\repo`
failed due to incorrect handling of the backslashes when handing the path
to the git-upload-pack process.

Further, we need to take care to quote not only whitespace and
backslashes, but also curly brackets. As aliases frequently go through
the MSYS2 Bash, and as aliases frequently get parameters such as
HEAD@{yesterday}, this is really important. As an early version of this
patch broke this, let's make sure that this does not regress by adding a
test case for that.

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

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-.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). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at https://public-inbox.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