unpack-trees: add a new update_sparsity() function

Previously, the only way to update the SKIP_WORKTREE bits for various
paths was invoking `git read-tree -mu HEAD` or calling the same code
that this codepath invoked.  This however had a number of problems if
the index or working directory were not clean.  First, let's consider
the case:

  Flipping SKIP_WORKTREE -> !SKIP_WORKTREE (materializing files)

If the working tree was clean this was fine, but if there were files or
directories or symlinks or whatever already present at the given path
then the operation would abort with an error.  Let's label this case
for later discussion:

    A) There is an untracked path in the way

Now let's consider the opposite case:

  Flipping !SKIP_WORKTREE -> SKIP_WORKTREE (removing files)

If the index and working tree was clean this was fine, but if there were
any unclean paths we would run into problems.  There are three different
cases to consider:

    B) The path is unmerged
    C) The path has unstaged changes
    D) The path has staged changes (differs from HEAD)

If any path fell into case B or C, then the whole operation would be
aborted with an error.  With sparse-checkout, the whole operation would
be aborted for case D as well, but for its predecessor of using `git
read-tree -mu HEAD` directly, any paths that fell into case D would be
removed from the working copy and the index entry for that path would be
reset to match HEAD -- which looks and feels like data loss to users
(only a few are even aware to ask whether it can be recovered, and even
then it requires walking through loose objects trying to match up the
right ones).

Refusing to remove files that have unsaved user changes is good, but
refusing to work on any other paths is very problematic for users.  If
the user is in the middle of a rebase or has made modifications to files
that bring in more dependencies, then for their build to work they need
to update the sparse paths.  This logic has been preventing them from
doing so.  Sometimes in response, the user will stage the files and
re-try, to no avail with sparse-checkout or to the horror of losing
their changes if they are using its predecessor of `git read-tree -mu
HEAD`.

Add a new update_sparsity() function which will not error out in any of
these cases but behaves as follows for the special cases:
    A) Leave the file in the working copy alone, clear the SKIP_WORKTREE
       bit, and print a warning (thus leaving the path in a state where
       status will report the file as modified, which seems logical).
    B) Do NOT mark this path as SKIP_WORKTREE, and leave it as unmerged.
    C) Do NOT mark this path as SKIP_WORKTREE and print a warning about
       the dirty path.
    D) Mark the path as SKIP_WORKTREE, but do not revert the version
       stored in the index to match HEAD; leave the contents alone.

I tried a different behavior for A (leave the SKIP_WORKTREE bit set),
but found it very surprising and counter-intuitive (e.g. the user sees
it is present along with all the other files in that directory, tries to
stage it, but git add ignores it since the SKIP_WORKTREE bit is set).  A
& C seem like optimal behavior to me.  B may be as well, though I wonder
if printing a warning would be an improvement.  Some might be slightly
surprised by D at first, but given that it does the right thing with
`git commit` and even `git commit -a` (`git add` ignores entries that
are marked SKIP_WORKTREE and thus doesn't delete them, and `commit -a`
is similar), it seems logical to me.

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