/t/t7063-status-untracked-cache.sh

https://gitlab.com/Blueprint-Marketing/git · Shell · 574 lines · 531 code · 40 blank · 3 comment · 1 complexity · 46f7d6e485efc3132a4b72d03a38e30b MD5 · raw file

  1. #!/bin/sh
  2. test_description='test untracked cache'
  3. . ./test-lib.sh
  4. avoid_racy() {
  5. sleep 1
  6. }
  7. # It's fine if git update-index returns an error code other than one,
  8. # it'll be caught in the first test.
  9. test_lazy_prereq UNTRACKED_CACHE '
  10. { git update-index --untracked-cache; ret=$?; } &&
  11. test $ret -ne 1
  12. '
  13. if ! test_have_prereq UNTRACKED_CACHE; then
  14. skip_all='This system does not support untracked cache'
  15. test_done
  16. fi
  17. test_expect_success 'setup' '
  18. git init worktree &&
  19. cd worktree &&
  20. mkdir done dtwo dthree &&
  21. touch one two three done/one dtwo/two dthree/three &&
  22. git add one two done/one &&
  23. : >.git/info/exclude &&
  24. git update-index --untracked-cache
  25. '
  26. test_expect_success 'untracked cache is empty' '
  27. test-dump-untracked-cache >../actual &&
  28. cat >../expect <<EOF &&
  29. info/exclude 0000000000000000000000000000000000000000
  30. core.excludesfile 0000000000000000000000000000000000000000
  31. exclude_per_dir .gitignore
  32. flags 00000006
  33. EOF
  34. test_cmp ../expect ../actual
  35. '
  36. cat >../status.expect <<EOF &&
  37. A done/one
  38. A one
  39. A two
  40. ?? dthree/
  41. ?? dtwo/
  42. ?? three
  43. EOF
  44. cat >../dump.expect <<EOF &&
  45. info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
  46. core.excludesfile 0000000000000000000000000000000000000000
  47. exclude_per_dir .gitignore
  48. flags 00000006
  49. / 0000000000000000000000000000000000000000 recurse valid
  50. dthree/
  51. dtwo/
  52. three
  53. /done/ 0000000000000000000000000000000000000000 recurse valid
  54. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  55. three
  56. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  57. two
  58. EOF
  59. test_expect_success 'status first time (empty cache)' '
  60. avoid_racy &&
  61. : >../trace &&
  62. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  63. git status --porcelain >../actual &&
  64. test_cmp ../status.expect ../actual &&
  65. cat >../trace.expect <<EOF &&
  66. node creation: 3
  67. gitignore invalidation: 1
  68. directory invalidation: 0
  69. opendir: 4
  70. EOF
  71. test_cmp ../trace.expect ../trace
  72. '
  73. test_expect_success 'untracked cache after first status' '
  74. test-dump-untracked-cache >../actual &&
  75. test_cmp ../dump.expect ../actual
  76. '
  77. test_expect_success 'status second time (fully populated cache)' '
  78. avoid_racy &&
  79. : >../trace &&
  80. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  81. git status --porcelain >../actual &&
  82. test_cmp ../status.expect ../actual &&
  83. cat >../trace.expect <<EOF &&
  84. node creation: 0
  85. gitignore invalidation: 0
  86. directory invalidation: 0
  87. opendir: 0
  88. EOF
  89. test_cmp ../trace.expect ../trace
  90. '
  91. test_expect_success 'untracked cache after second status' '
  92. test-dump-untracked-cache >../actual &&
  93. test_cmp ../dump.expect ../actual
  94. '
  95. test_expect_success 'modify in root directory, one dir invalidation' '
  96. avoid_racy &&
  97. : >four &&
  98. : >../trace &&
  99. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  100. git status --porcelain >../actual &&
  101. cat >../status.expect <<EOF &&
  102. A done/one
  103. A one
  104. A two
  105. ?? dthree/
  106. ?? dtwo/
  107. ?? four
  108. ?? three
  109. EOF
  110. test_cmp ../status.expect ../actual &&
  111. cat >../trace.expect <<EOF &&
  112. node creation: 0
  113. gitignore invalidation: 0
  114. directory invalidation: 1
  115. opendir: 1
  116. EOF
  117. test_cmp ../trace.expect ../trace
  118. '
  119. test_expect_success 'verify untracked cache dump' '
  120. test-dump-untracked-cache >../actual &&
  121. cat >../expect <<EOF &&
  122. info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
  123. core.excludesfile 0000000000000000000000000000000000000000
  124. exclude_per_dir .gitignore
  125. flags 00000006
  126. / 0000000000000000000000000000000000000000 recurse valid
  127. dthree/
  128. dtwo/
  129. four
  130. three
  131. /done/ 0000000000000000000000000000000000000000 recurse valid
  132. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  133. three
  134. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  135. two
  136. EOF
  137. test_cmp ../expect ../actual
  138. '
  139. test_expect_success 'new .gitignore invalidates recursively' '
  140. avoid_racy &&
  141. echo four >.gitignore &&
  142. : >../trace &&
  143. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  144. git status --porcelain >../actual &&
  145. cat >../status.expect <<EOF &&
  146. A done/one
  147. A one
  148. A two
  149. ?? .gitignore
  150. ?? dthree/
  151. ?? dtwo/
  152. ?? three
  153. EOF
  154. test_cmp ../status.expect ../actual &&
  155. cat >../trace.expect <<EOF &&
  156. node creation: 0
  157. gitignore invalidation: 1
  158. directory invalidation: 1
  159. opendir: 4
  160. EOF
  161. test_cmp ../trace.expect ../trace
  162. '
  163. test_expect_success 'verify untracked cache dump' '
  164. test-dump-untracked-cache >../actual &&
  165. cat >../expect <<EOF &&
  166. info/exclude e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
  167. core.excludesfile 0000000000000000000000000000000000000000
  168. exclude_per_dir .gitignore
  169. flags 00000006
  170. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  171. .gitignore
  172. dthree/
  173. dtwo/
  174. three
  175. /done/ 0000000000000000000000000000000000000000 recurse valid
  176. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  177. three
  178. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  179. two
  180. EOF
  181. test_cmp ../expect ../actual
  182. '
  183. test_expect_success 'new info/exclude invalidates everything' '
  184. avoid_racy &&
  185. echo three >>.git/info/exclude &&
  186. : >../trace &&
  187. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  188. git status --porcelain >../actual &&
  189. cat >../status.expect <<EOF &&
  190. A done/one
  191. A one
  192. A two
  193. ?? .gitignore
  194. ?? dtwo/
  195. EOF
  196. test_cmp ../status.expect ../actual &&
  197. cat >../trace.expect <<EOF &&
  198. node creation: 0
  199. gitignore invalidation: 1
  200. directory invalidation: 0
  201. opendir: 4
  202. EOF
  203. test_cmp ../trace.expect ../trace
  204. '
  205. test_expect_success 'verify untracked cache dump' '
  206. test-dump-untracked-cache >../actual &&
  207. cat >../expect <<EOF &&
  208. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  209. core.excludesfile 0000000000000000000000000000000000000000
  210. exclude_per_dir .gitignore
  211. flags 00000006
  212. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  213. .gitignore
  214. dtwo/
  215. /done/ 0000000000000000000000000000000000000000 recurse valid
  216. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  217. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  218. two
  219. EOF
  220. test_cmp ../expect ../actual
  221. '
  222. test_expect_success 'move two from tracked to untracked' '
  223. git rm --cached two &&
  224. test-dump-untracked-cache >../actual &&
  225. cat >../expect <<EOF &&
  226. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  227. core.excludesfile 0000000000000000000000000000000000000000
  228. exclude_per_dir .gitignore
  229. flags 00000006
  230. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
  231. /done/ 0000000000000000000000000000000000000000 recurse valid
  232. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  233. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  234. two
  235. EOF
  236. test_cmp ../expect ../actual
  237. '
  238. test_expect_success 'status after the move' '
  239. : >../trace &&
  240. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  241. git status --porcelain >../actual &&
  242. cat >../status.expect <<EOF &&
  243. A done/one
  244. A one
  245. ?? .gitignore
  246. ?? dtwo/
  247. ?? two
  248. EOF
  249. test_cmp ../status.expect ../actual &&
  250. cat >../trace.expect <<EOF &&
  251. node creation: 0
  252. gitignore invalidation: 0
  253. directory invalidation: 0
  254. opendir: 1
  255. EOF
  256. test_cmp ../trace.expect ../trace
  257. '
  258. test_expect_success 'verify untracked cache dump' '
  259. test-dump-untracked-cache >../actual &&
  260. cat >../expect <<EOF &&
  261. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  262. core.excludesfile 0000000000000000000000000000000000000000
  263. exclude_per_dir .gitignore
  264. flags 00000006
  265. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  266. .gitignore
  267. dtwo/
  268. two
  269. /done/ 0000000000000000000000000000000000000000 recurse valid
  270. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  271. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  272. two
  273. EOF
  274. test_cmp ../expect ../actual
  275. '
  276. test_expect_success 'move two from untracked to tracked' '
  277. git add two &&
  278. test-dump-untracked-cache >../actual &&
  279. cat >../expect <<EOF &&
  280. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  281. core.excludesfile 0000000000000000000000000000000000000000
  282. exclude_per_dir .gitignore
  283. flags 00000006
  284. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse
  285. /done/ 0000000000000000000000000000000000000000 recurse valid
  286. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  287. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  288. two
  289. EOF
  290. test_cmp ../expect ../actual
  291. '
  292. test_expect_success 'status after the move' '
  293. : >../trace &&
  294. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  295. git status --porcelain >../actual &&
  296. cat >../status.expect <<EOF &&
  297. A done/one
  298. A one
  299. A two
  300. ?? .gitignore
  301. ?? dtwo/
  302. EOF
  303. test_cmp ../status.expect ../actual &&
  304. cat >../trace.expect <<EOF &&
  305. node creation: 0
  306. gitignore invalidation: 0
  307. directory invalidation: 0
  308. opendir: 1
  309. EOF
  310. test_cmp ../trace.expect ../trace
  311. '
  312. test_expect_success 'verify untracked cache dump' '
  313. test-dump-untracked-cache >../actual &&
  314. cat >../expect <<EOF &&
  315. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  316. core.excludesfile 0000000000000000000000000000000000000000
  317. exclude_per_dir .gitignore
  318. flags 00000006
  319. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  320. .gitignore
  321. dtwo/
  322. /done/ 0000000000000000000000000000000000000000 recurse valid
  323. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  324. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  325. two
  326. EOF
  327. test_cmp ../expect ../actual
  328. '
  329. test_expect_success 'set up for sparse checkout testing' '
  330. echo two >done/.gitignore &&
  331. echo three >>done/.gitignore &&
  332. echo two >done/two &&
  333. git add -f done/two done/.gitignore &&
  334. git commit -m "first commit"
  335. '
  336. test_expect_success 'status after commit' '
  337. : >../trace &&
  338. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  339. git status --porcelain >../actual &&
  340. cat >../status.expect <<EOF &&
  341. ?? .gitignore
  342. ?? dtwo/
  343. EOF
  344. test_cmp ../status.expect ../actual &&
  345. cat >../trace.expect <<EOF &&
  346. node creation: 0
  347. gitignore invalidation: 0
  348. directory invalidation: 0
  349. opendir: 2
  350. EOF
  351. test_cmp ../trace.expect ../trace
  352. '
  353. test_expect_success 'untracked cache correct after commit' '
  354. test-dump-untracked-cache >../actual &&
  355. cat >../expect <<EOF &&
  356. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  357. core.excludesfile 0000000000000000000000000000000000000000
  358. exclude_per_dir .gitignore
  359. flags 00000006
  360. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  361. .gitignore
  362. dtwo/
  363. /done/ 0000000000000000000000000000000000000000 recurse valid
  364. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  365. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  366. two
  367. EOF
  368. test_cmp ../expect ../actual
  369. '
  370. test_expect_success 'set up sparse checkout' '
  371. echo "done/[a-z]*" >.git/info/sparse-checkout &&
  372. test_config core.sparsecheckout true &&
  373. git checkout master &&
  374. git update-index --force-untracked-cache &&
  375. git status --porcelain >/dev/null && # prime the cache
  376. test_path_is_missing done/.gitignore &&
  377. test_path_is_file done/one
  378. '
  379. test_expect_success 'create/modify files, some of which are gitignored' '
  380. echo two bis >done/two &&
  381. echo three >done/three && # three is gitignored
  382. echo four >done/four && # four is gitignored at a higher level
  383. echo five >done/five && # five is not gitignored
  384. echo test >base && #we need to ensure that the root dir is touched
  385. rm base
  386. '
  387. test_expect_success 'test sparse status with untracked cache' '
  388. : >../trace &&
  389. avoid_racy &&
  390. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  391. git status --porcelain >../status.actual &&
  392. cat >../status.expect <<EOF &&
  393. M done/two
  394. ?? .gitignore
  395. ?? done/five
  396. ?? dtwo/
  397. EOF
  398. test_cmp ../status.expect ../status.actual &&
  399. cat >../trace.expect <<EOF &&
  400. node creation: 0
  401. gitignore invalidation: 1
  402. directory invalidation: 2
  403. opendir: 2
  404. EOF
  405. test_cmp ../trace.expect ../trace
  406. '
  407. test_expect_success 'untracked cache correct after status' '
  408. test-dump-untracked-cache >../actual &&
  409. cat >../expect <<EOF &&
  410. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  411. core.excludesfile 0000000000000000000000000000000000000000
  412. exclude_per_dir .gitignore
  413. flags 00000006
  414. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  415. .gitignore
  416. dtwo/
  417. /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
  418. five
  419. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  420. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  421. two
  422. EOF
  423. test_cmp ../expect ../actual
  424. '
  425. test_expect_success 'test sparse status again with untracked cache' '
  426. avoid_racy &&
  427. : >../trace &&
  428. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  429. git status --porcelain >../status.actual &&
  430. cat >../status.expect <<EOF &&
  431. M done/two
  432. ?? .gitignore
  433. ?? done/five
  434. ?? dtwo/
  435. EOF
  436. test_cmp ../status.expect ../status.actual &&
  437. cat >../trace.expect <<EOF &&
  438. node creation: 0
  439. gitignore invalidation: 0
  440. directory invalidation: 0
  441. opendir: 0
  442. EOF
  443. test_cmp ../trace.expect ../trace
  444. '
  445. test_expect_success 'set up for test of subdir and sparse checkouts' '
  446. mkdir done/sub &&
  447. mkdir done/sub/sub &&
  448. echo "sub" > done/sub/sub/file
  449. '
  450. test_expect_success 'test sparse status with untracked cache and subdir' '
  451. avoid_racy &&
  452. : >../trace &&
  453. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  454. git status --porcelain >../status.actual &&
  455. cat >../status.expect <<EOF &&
  456. M done/two
  457. ?? .gitignore
  458. ?? done/five
  459. ?? done/sub/
  460. ?? dtwo/
  461. EOF
  462. test_cmp ../status.expect ../status.actual &&
  463. cat >../trace.expect <<EOF &&
  464. node creation: 2
  465. gitignore invalidation: 0
  466. directory invalidation: 1
  467. opendir: 3
  468. EOF
  469. test_cmp ../trace.expect ../trace
  470. '
  471. test_expect_success 'verify untracked cache dump (sparse/subdirs)' '
  472. test-dump-untracked-cache >../actual &&
  473. cat >../expect <<EOF &&
  474. info/exclude 13263c0978fb9fad16b2d580fb800b6d811c3ff0
  475. core.excludesfile 0000000000000000000000000000000000000000
  476. exclude_per_dir .gitignore
  477. flags 00000006
  478. / e6fcc8f2ee31bae321d66afd183fcb7237afae6e recurse valid
  479. .gitignore
  480. dtwo/
  481. /done/ 1946f0437f90c5005533cbe1736a6451ca301714 recurse valid
  482. five
  483. sub/
  484. /done/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
  485. sub/
  486. /done/sub/sub/ 0000000000000000000000000000000000000000 recurse check_only valid
  487. file
  488. /dthree/ 0000000000000000000000000000000000000000 recurse check_only valid
  489. /dtwo/ 0000000000000000000000000000000000000000 recurse check_only valid
  490. two
  491. EOF
  492. test_cmp ../expect ../actual
  493. '
  494. test_expect_success 'test sparse status again with untracked cache and subdir' '
  495. avoid_racy &&
  496. : >../trace &&
  497. GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace" \
  498. git status --porcelain >../status.actual &&
  499. test_cmp ../status.expect ../status.actual &&
  500. cat >../trace.expect <<EOF &&
  501. node creation: 0
  502. gitignore invalidation: 0
  503. directory invalidation: 0
  504. opendir: 0
  505. EOF
  506. test_cmp ../trace.expect ../trace
  507. '
  508. test_expect_success 'move entry in subdir from untracked to cached' '
  509. git add dtwo/two &&
  510. git status --porcelain >../status.actual &&
  511. cat >../status.expect <<EOF &&
  512. M done/two
  513. A dtwo/two
  514. ?? .gitignore
  515. ?? done/five
  516. ?? done/sub/
  517. EOF
  518. test_cmp ../status.expect ../status.actual
  519. '
  520. test_expect_success 'move entry in subdir from cached to untracked' '
  521. git rm --cached dtwo/two &&
  522. git status --porcelain >../status.actual &&
  523. cat >../status.expect <<EOF &&
  524. M done/two
  525. ?? .gitignore
  526. ?? done/five
  527. ?? done/sub/
  528. ?? dtwo/
  529. EOF
  530. test_cmp ../status.expect ../status.actual
  531. '
  532. test_done