Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t7063-status-untracked-cache.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t7063-status-untracked-cache.sh` 994 lines ยท 27199 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='test untracked cache' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 # On some filesystems (e.g. FreeBSD's ext2 and ufs) directory mtime 11 # is updated lazily after contents in the directory changes, which 12 # forces the untracked cache code to take the slow path. A test 13 # that wants to make sure that the fast path works correctly should 14 # call this helper to make mtime of the containing directory in sync 15 # with the reality before checking the fast path behaviour. 16 # 17 # See <`20160803174522`.5571-1-pclouds@gmail.com> if you want to know 18 # more. 19 20 GIT_FORCE_UNTRACKED_CACHE=true 21 export GIT_FORCE_UNTRACKED_CACHE 22 23 sync_mtime () { 24 find . -type d -exec ls -ld {} + >/dev/null 25 } 26 27 avoid_racy() { 28 sleep 1 29 } 30 31 status_is_clean() { 32 git status --porcelain >../status.actual && 33 test_must_be_empty ../status.actual 34 } 35 36 # Ignore_Untracked_Cache, abbreviated to 3 letters because then people can 37 # compare commands side-by-side, e.g. 38 # iuc status --porcelain >expect && 39 # git status --porcelain >actual && 40 # test_cmp expect actual 41 iuc () { 42 git ls-files -s >../current-index-entries 43 git ls-files -t | sed -ne s/^S.//p >../current-sparse-entries 44 45 GIT_INDEX_FILE=.git/tmp_index 46 export GIT_INDEX_FILE 47 git update-index --index-info <../current-index-entries 48 git update-index --skip-worktree $(cat ../current-sparse-entries) 49 50 git -c core.untrackedCache=false "$@" 51 ret=$? 52 53 rm ../current-index-entries 54 rm $GIT_INDEX_FILE 55 unset GIT_INDEX_FILE 56 57 return $ret 58 } 59 60 get_relevant_traces () { 61 # From the GIT_TRACE2_PERF data of the form 62 # $TIME $FILE:$LINE | d0 | main | data | r1 | ? | ? | read_directo | $RELEVANT_STAT 63 # extract the $RELEVANT_STAT fields. We don't care about region_enter 64 # or region_leave, or stats for things outside read_directory. 65 INPUT_FILE=$1 66 OUTPUT_FILE=$2 67 grep data.*read_directo $INPUT_FILE | 68 cut -d "|" -f 9 | 69 grep -v visited \ 70 >"$OUTPUT_FILE" 71 } 72 73 74 test_lazy_prereq UNTRACKED_CACHE ' 75 { git update-index --test-untracked-cache; ret=$?; } && 76 test $ret -ne 1 77 ' 78 79 if ! test_have_prereq UNTRACKED_CACHE; then 80 skip_all='This system does not support untracked cache' 81 test_done 82 fi 83 84 test_expect_success 'core.untrackedCache is unset' ' 85 test_must_fail git config --get core.untrackedCache 86 ' 87 88 test_expect_success 'setup' ' 89 git init --template= worktree && 90 cd worktree && 91 mkdir done dtwo dthree && 92 touch one two three done/one dtwo/two dthree/three && 93 test-tool chmtime =-300 one two three done/one dtwo/two dthree/three && 94 test-tool chmtime =-300 done dtwo dthree && 95 test-tool chmtime =-300 . && 96 git add one two done/one && 97 mkdir .git/info && 98 : >.git/info/exclude && 99 git update-index --untracked-cache && 100 test_oid_cache <<-EOF 101 root sha1:`e6fcc8f2ee31bae321d66afd183fcb7237afae6e` 102 root sha256:`b90c672088c015b9c83876e919da311bad4cd39639fb139f988af6a11493b974` 103 104 exclude sha1:`13263c0978fb9fad16b2d580fb800b6d811c3ff0` 105 exclude sha256:`fe4aaa1bbbbce4cb8f73426748a14c5ad6026b26f90505a0bf2494b165a5b76c` 106 107 done sha1:`1946f0437f90c5005533cbe1736a6451ca301714` 108 done sha256:`7f079501d79f665b3acc50f5e0e9e94509084d5032ac20113a37dd5029b757cc` 109 EOF 110 ' 111 112 test_expect_success 'untracked cache is empty' ' 113 test-tool dump-untracked-cache >../actual && 114 cat >../expect-empty <../status.expect <../dump.expect <../trace.output && 150 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 151 git status --porcelain >../actual && 152 iuc status --porcelain >../status.iuc && 153 test_cmp ../status.expect ../status.iuc && 154 test_cmp ../status.expect ../actual && 155 get_relevant_traces ../trace.output ../trace.relevant && 156 cat >../trace.expect <../actual && 168 test_cmp ../dump.expect ../actual 169 ' 170 171 test_expect_success 'status second time (fully populated cache)' ' 172 : >../trace.output && 173 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 174 git status --porcelain >../actual && 175 iuc status --porcelain >../status.iuc && 176 test_cmp ../status.expect ../status.iuc && 177 test_cmp ../status.expect ../actual && 178 get_relevant_traces ../trace.output ../trace.relevant && 179 cat >../trace.expect <../actual && 191 test_cmp ../dump.expect ../actual 192 ' 193 194 cat >../status_uall.expect <../trace.output && 209 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 210 git status -uall --porcelain >../actual && 211 iuc status -uall --porcelain >../status.iuc && 212 test_cmp ../status_uall.expect ../status.iuc && 213 test_cmp ../status_uall.expect ../actual && 214 get_relevant_traces ../trace.output ../trace.relevant && 215 cat >../trace.expect <../actual && 223 test_cmp ../dump.expect ../actual 224 ' 225 226 test_expect_success 'if -uall is configured, untracked cache gets populated by default' ' 227 test_config status.showuntrackedfiles all && 228 : >../trace.output && 229 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 230 git status --porcelain >../actual && 231 iuc status --porcelain >../status.iuc && 232 test_cmp ../status_uall.expect ../status.iuc && 233 test_cmp ../status_uall.expect ../actual && 234 get_relevant_traces ../trace.output ../trace.relevant && 235 cat >../trace.expect <../dump_uall.expect <../actual && 261 test_cmp ../dump_uall.expect ../actual 262 ' 263 264 test_expect_success 'if -uall is configured, untracked cache is used by default' ' 265 test_config status.showuntrackedfiles all && 266 : >../trace.output && 267 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 268 git status --porcelain >../actual && 269 iuc status --porcelain >../status.iuc && 270 test_cmp ../status_uall.expect ../status.iuc && 271 test_cmp ../status_uall.expect ../actual && 272 get_relevant_traces ../trace.output ../trace.relevant && 273 cat >../trace.expect <../trace.output && 291 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 292 git status -unormal --porcelain >../actual && 293 iuc status -unormal --porcelain >../status.iuc && 294 test_cmp ../status.expect ../status.iuc && 295 test_cmp ../status.expect ../actual && 296 get_relevant_traces ../trace.output ../trace.relevant && 297 cat >../trace.expect <four && 309 test-tool chmtime =-240 four && 310 : >../trace.output && 311 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 312 git status --porcelain >../actual && 313 iuc status --porcelain >../status.iuc && 314 cat >../status.expect <../trace.expect <../actual && 339 cat >../expect <.gitignore && 360 : >../trace.output && 361 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 362 git status --porcelain >../actual && 363 iuc status --porcelain >../status.iuc && 364 cat >../status.expect <../trace.expect <../actual && 389 cat >../expect <>.git/info/exclude && 410 : >../trace.output && 411 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 412 git status --porcelain >../actual && 413 iuc status --porcelain >../status.iuc && 414 cat >../status.expect <../trace.expect <../actual && 436 cat >../expect <../actual && 455 cat >../expect <../trace.output && 471 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 472 git status --porcelain >../actual && 473 iuc status --porcelain >../status.iuc && 474 cat >../status.expect <../trace.expect <../actual && 496 cat >../expect <../actual && 516 cat >../expect <../trace.output && 532 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 533 git status --porcelain >../actual && 534 iuc status --porcelain >../status.iuc && 535 cat >../status.expect <../trace.expect <../actual && 557 cat >../expect <done/.gitignore && 575 echo three >>done/.gitignore && 576 echo two >done/two && 577 git add -f done/two done/.gitignore && 578 git commit -m "first commit" 579 ' 580 581 test_expect_success 'status after commit' ' 582 : >../trace.output && 583 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 584 git status --porcelain >../actual && 585 iuc status --porcelain >../status.iuc && 586 cat >../status.expect <../trace.expect <../actual && 605 cat >../expect <.git/info/sparse-checkout && 623 test_config core.sparsecheckout true && 624 git checkout main && 625 git update-index --force-untracked-cache && 626 git status --porcelain >/dev/null && # prime the cache 627 test_path_is_missing done/.gitignore && 628 test_path_is_file done/one 629 ' 630 631 test_expect_success 'create/modify files, some of which are gitignored' ' 632 echo two bis >done/two && 633 echo three >done/three && # three is gitignored 634 echo four >done/four && # four is gitignored at a higher level 635 echo five >done/five && # five is not gitignored 636 test-tool chmtime =-180 done/two done/three done/four done/five done && 637 # we need to ensure that the root dir is touched (in the past); 638 test-tool chmtime =-180 . && 639 sync_mtime 640 ' 641 642 test_expect_success 'test sparse status with untracked cache' ' 643 : >../trace.output && 644 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 645 git status --porcelain >../status.actual && 646 iuc status --porcelain >../status.iuc && 647 cat >../status.expect <../trace.expect <../actual && 668 cat >../expect <../trace.output && 687 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 688 git status --porcelain >../status.actual && 689 iuc status --porcelain >../status.iuc && 690 cat >../status.expect <../trace.expect < done/sub/sub/file && 713 test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done 714 ' 715 716 test_expect_success 'test sparse status with untracked cache and subdir' ' 717 : >../trace.output && 718 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 719 git status --porcelain >../status.actual && 720 iuc status --porcelain >../status.iuc && 721 cat >../status.expect <../trace.expect <../actual && 743 cat >../expect-from-test-dump <../trace.output && 767 GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \ 768 git status --porcelain >../status.actual && 769 iuc status --porcelain >../status.iuc && 770 test_cmp ../status.expect ../status.iuc && 771 test_cmp ../status.expect ../status.actual && 772 get_relevant_traces ../trace.output ../trace.relevant && 773 cat >../trace.expect <../status.actual && 786 iuc status --porcelain >../status.iuc && 787 cat >../status.expect <../status.actual && 801 iuc status --porcelain >../status.iuc && 802 cat >../status.expect <../actual && 816 echo "no untracked cache" >../expect-no-uc && 817 test_cmp ../expect-no-uc ../actual 818 ' 819 820 test_expect_success 'git status does not change anything' ' 821 git status && 822 test-tool dump-untracked-cache >../actual && 823 test_cmp ../expect-no-uc ../actual 824 ' 825 826 test_expect_success 'setting core.untrackedCache to true and using git status creates the cache' ' 827 git config core.untrackedCache true && 828 test-tool dump-untracked-cache >../actual && 829 test_cmp ../expect-no-uc ../actual && 830 git status && 831 test-tool dump-untracked-cache >../actual && 832 test_cmp ../expect-from-test-dump ../actual 833 ' 834 835 test_expect_success 'using --no-untracked-cache does not fail when core.untrackedCache is true' ' 836 git update-index --no-untracked-cache && 837 test-tool dump-untracked-cache >../actual && 838 test_cmp ../expect-no-uc ../actual && 839 git update-index --untracked-cache && 840 test-tool dump-untracked-cache >../actual && 841 test_cmp ../expect-empty ../actual 842 ' 843 844 test_expect_success 'setting core.untrackedCache to false and using git status removes the cache' ' 845 git config core.untrackedCache false && 846 test-tool dump-untracked-cache >../actual && 847 test_cmp ../expect-empty ../actual && 848 git status && 849 test-tool dump-untracked-cache >../actual && 850 test_cmp ../expect-no-uc ../actual 851 ' 852 853 test_expect_success 'using --untracked-cache does not fail when core.untrackedCache is false' ' 854 git update-index --untracked-cache && 855 test-tool dump-untracked-cache >../actual && 856 test_cmp ../expect-empty ../actual 857 ' 858 859 test_expect_success 'setting core.untrackedCache to keep' ' 860 git config core.untrackedCache keep && 861 git update-index --untracked-cache && 862 test-tool dump-untracked-cache >../actual && 863 test_cmp ../expect-empty ../actual && 864 git status && 865 test-tool dump-untracked-cache >../actual && 866 test_cmp ../expect-from-test-dump ../actual && 867 git update-index --no-untracked-cache && 868 test-tool dump-untracked-cache >../actual && 869 test_cmp ../expect-no-uc ../actual && 870 git update-index --force-untracked-cache && 871 test-tool dump-untracked-cache >../actual && 872 test_cmp ../expect-empty ../actual && 873 git status && 874 test-tool dump-untracked-cache >../actual && 875 test_cmp ../expect-from-test-dump ../actual 876 ' 877 878 test_expect_success 'test ident field is working' ' 879 mkdir ../other_worktree && 880 cp -R done dthree dtwo four three ../other_worktree && 881 GIT_WORK_TREE=../other_worktree git status 2>../err && 882 echo "warning: untracked cache is disabled on this system or location" >../expect && 883 test_cmp ../expect ../err 884 ' 885 886 test_expect_success 'untracked cache survives a checkout' ' 887 git commit --allow-empty -m empty && 888 test-tool dump-untracked-cache >../before && 889 test_when_finished "git checkout main" && 890 git checkout -b other_branch && 891 test-tool dump-untracked-cache >../after && 892 test_cmp ../before ../after && 893 test_commit test && 894 test-tool dump-untracked-cache >../before && 895 git checkout main && 896 test-tool dump-untracked-cache >../after && 897 test_cmp ../before ../after 898 ' 899 900 test_expect_success 'untracked cache survives a commit' ' 901 test-tool dump-untracked-cache >../before && 902 git add done/two && 903 git commit -m commit && 904 test-tool dump-untracked-cache >../after && 905 test_cmp ../before ../after 906 ' 907 908 test_expect_success 'teardown worktree' ' 909 cd .. 910 ' 911 912 test_expect_success SYMLINKS 'setup worktree for symlink test' ' 913 git init worktree-symlink && 914 cd worktree-symlink && 915 git config core.untrackedCache true && 916 mkdir one two && 917 touch one/file two/file && 918 git add one/file two/file && 919 git commit -m"first commit" && 920 git rm -rf one && 921 ln -s two one && 922 git add one && 923 git commit -m"second commit" 924 ' 925 926 test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=true' ' 927 git checkout HEAD~ && 928 status_is_clean && 929 status_is_clean && 930 git checkout main && 931 avoid_racy && 932 status_is_clean && 933 status_is_clean 934 ' 935 936 test_expect_success SYMLINKS '"status" after symlink replacement should be clean with UC=false' ' 937 git config core.untrackedCache false && 938 git checkout HEAD~ && 939 status_is_clean && 940 status_is_clean && 941 git checkout main && 942 avoid_racy && 943 status_is_clean && 944 status_is_clean 945 ' 946 947 test_expect_success 'setup worktree for non-symlink test' ' 948 git init worktree-non-symlink && 949 cd worktree-non-symlink && 950 git config core.untrackedCache true && 951 mkdir one two && 952 touch one/file two/file && 953 git add one/file two/file && 954 git commit -m"first commit" && 955 git rm -rf one && 956 cp two/file one && 957 git add one && 958 git commit -m"second commit" 959 ' 960 961 test_expect_success '"status" after file replacement should be clean with UC=true' ' 962 git checkout HEAD~ && 963 status_is_clean && 964 status_is_clean && 965 git checkout main && 966 avoid_racy && 967 status_is_clean && 968 test-tool dump-untracked-cache >../actual && 969 grep -F "recurse valid" ../actual >../actual.grep && 970 cat >../expect.grep <