submodule foreach: correct '$path' in nested submodules from a subdirectory

When running 'git submodule foreach --recursive' from a subdirectory of
your repository, nested submodules get a bogus value for $path:
For a submodule 'sub' that contains a nested submodule 'nested',
running 'git -C dir submodule foreach echo $path' from the root of the
superproject would report path='../nested' for the nested submodule.
The first part '../' is derived from the logic computing the relative
path from $pwd to the root of the superproject. The second part is the
submodule path inside the submodule. This value is of little use and is
hard to document.

Also, in git-submodule.txt, $path is documented to be the "name of the
submodule directory relative to the superproject", but "the
superproject" is ambiguous.

To resolve both these issues, we could:
(a) Change "the superproject" to "its immediate superproject", so
    $path would be "nested" instead of "../nested".
(b) Change "the superproject" to "the superproject the original
    command was run from", so $path would be "sub/nested" instead of
    "../nested".
(c) Change "the superproject" to "the directory the original command
    was run from", so $path would be "../sub/nested" instead of
    "../nested".

The behavior for (c) was attempted to be introduced in 091a6eb0fe
(submodule: drop the top-level requirement, 2013-06-16) with the intent
for $path to be relative from $pwd to the submodule worktree, but that
did not work for nested submodules, as the intermittent submodules
were not included in the path.

If we were to fix the meaning of the $path using (a), we would break
any existing submodule user that runs foreach from non-root of the
superproject as the non-nested submodule '../sub' would change its
path to 'sub'.

If we were to fix the meaning of $path using (b), then we would break
any user that uses nested submodules (even from the root directory)
as the 'nested' would become 'sub/nested'.

If we were to fix the meaning of $path using (c), then we would break
the same users as in (b) as 'nested' would become 'sub/nested' from
the root directory of the superproject.

All groups can be found in the wild.  The author has no data if one group
outweighs the other by large margin, and offending each one seems equally
bad at first.  However in the authors imagination it is better to go with
(a) as running from a sub directory sounds like it is carried out by a
human rather than by some automation task.  With a human on the keyboard
the feedback loop is short and the changed behavior can be adapted to
quickly unlike some automation that can break silently.

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

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