submodule: unset core.worktree if no working tree is present

When a submodules work tree is removed, we should unset its core.worktree
setting as the worktree is no longer present. This is not just in line
with the conceptual view of submodules, but it fixes an inconvenience
for looking at submodules that are not checked out:

    git clone --recurse-submodules git://github.com/git/git && cd git &&
    git checkout --recurse-submodules v2.13.0
    git -C .git/modules/sha1collisiondetection log
    fatal: cannot chdir to '../../../sha1collisiondetection': \
        No such file or directory

With this patch applied, the final call to git log works instead of dying
in its setup, as the checkout will unset the core.worktree setting such
that following log will be run in a bare repository.

This patch covers all commands that are in the unpack machinery, i.e.
checkout, read-tree, reset. A follow up patch will address
"git submodule deinit", which will also make use of the new function
submodule_unset_core_worktree(), which is why we expose it in this patch.

This patch was authored as 4fa4f90ccd (submodule: unset core.worktree if
no working tree is present, 2018-06-12), which was reverted as part of
f178c13fda (Revert "Merge branch 'sb/submodule-core-worktree'",
2018-09-07). The revert was needed as the nearby commit e98317508c
(submodule: ensure core.worktree is set after update, 2018-06-18) is
faulty and at the time of 7e25437d35 (Merge branch
'sb/submodule-core-worktree', 2018-07-18) we could not revert the faulty
commit only, as they were depending on each other: If core.worktree is
unset, we have to have ways to ensure that it is set again once
the working tree reappears again.

Now that 4d6d6ef1fc (Merge branch 'sb/submodule-update-in-c', 2018-09-17),
specifically 74d4731da1 (submodule--helper: replace
connect-gitdir-workingtree by ensure-core-worktree, 2018-08-13) is
present, we already check and ensure core.worktree is set when
populating a new work tree, such that we can re-introduce the commits
that unset core.worktree when removing the worktree.

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>
3 files changed
tree: c1cad52bd6bc29f122e49c1a986949045bc70948
  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