Imported Upstream version 2.25.4
[platform/upstream/git.git] / t / t7519-status-fsmonitor.sh
index 756beb0..cf0fda2 100755 (executable)
@@ -4,13 +4,6 @@ test_description='git status with file system watcher'
 
 . ./test-lib.sh
 
-#
-# To run the entire git test suite using fsmonitor:
-#
-# copy t/t7519/fsmonitor-all to a location in your path and then set
-# GIT_FSMONITOR_TEST=fsmonitor-all and run your tests.
-#
-
 # Note, after "git reset --hard HEAD" no extensions exist other than 'TREE'
 # "git update-index --fsmonitor" can be used to get the extension written
 # before testing the results.
@@ -84,21 +77,21 @@ test_expect_success 'setup' '
 
 # test that the fsmonitor extension is off by default
 test_expect_success 'fsmonitor extension is off by default' '
-       test-dump-fsmonitor >actual &&
+       test-tool dump-fsmonitor >actual &&
        grep "^no fsmonitor" actual
 '
 
 # test that "update-index --fsmonitor" adds the fsmonitor extension
 test_expect_success 'update-index --fsmonitor" adds the fsmonitor extension' '
        git update-index --fsmonitor &&
-       test-dump-fsmonitor >actual &&
+       test-tool dump-fsmonitor >actual &&
        grep "^fsmonitor last update" actual
 '
 
 # test that "update-index --no-fsmonitor" removes the fsmonitor extension
 test_expect_success 'update-index --no-fsmonitor" removes the fsmonitor extension' '
        git update-index --no-fsmonitor &&
-       test-dump-fsmonitor >actual &&
+       test-tool dump-fsmonitor >actual &&
        grep "^no fsmonitor" actual
 '
 
@@ -113,6 +106,8 @@ EOF
 
 # test that "update-index --fsmonitor-valid" sets the fsmonitor valid bit
 test_expect_success 'update-index --fsmonitor-valid" sets the fsmonitor valid bit' '
+       write_script .git/hooks/fsmonitor-test<<-\EOF &&
+       EOF
        git update-index --fsmonitor &&
        git update-index --fsmonitor-valid dir1/modified &&
        git update-index --fsmonitor-valid dir2/modified &&
@@ -171,6 +166,8 @@ EOF
 
 # test that newly added files are marked valid
 test_expect_success 'newly added files are marked valid' '
+       write_script .git/hooks/fsmonitor-test<<-\EOF &&
+       EOF
        git add new &&
        git add dir1/new &&
        git add dir2/new &&
@@ -225,11 +222,12 @@ test_expect_success '*only* files returned by the integration script get flagged
 # Ensure commands that call refresh_index() to move the index back in time
 # properly invalidate the fsmonitor cache
 test_expect_success 'refresh_index() invalidates fsmonitor cache' '
-       write_script .git/hooks/fsmonitor-test<<-\EOF &&
-       EOF
        clean_repo &&
        dirty_repo &&
+       write_integration_script &&
        git add . &&
+       write_script .git/hooks/fsmonitor-test<<-\EOF &&
+       EOF
        git commit -m "to reset" &&
        git reset HEAD~1 &&
        git status >actual &&
@@ -245,9 +243,9 @@ do
                git config core.preloadIndex $preload_val &&
                if test $preload_val = true
                then
-                       GIT_FORCE_PRELOAD_TEST=$preload_val; export GIT_FORCE_PRELOAD_TEST
+                       GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX
                else
-                       unset GIT_FORCE_PRELOAD_TEST
+                       sane_unset GIT_TEST_PRELOAD_INDEX
                fi
        '
 
@@ -301,15 +299,15 @@ do
        done
 done
 
-# test that splitting the index dosn't interfere
+# test that splitting the index doesn't interfere
 test_expect_success 'splitting the index results in the same state' '
        write_integration_script &&
        dirty_repo &&
        git update-index --fsmonitor  &&
        git ls-files -f >expect &&
-       test-dump-fsmonitor >&2 && echo &&
+       test-tool dump-fsmonitor >&2 && echo &&
        git update-index --fsmonitor --split-index &&
-       test-dump-fsmonitor >&2 && echo &&
+       test-tool dump-fsmonitor >&2 && echo &&
        git ls-files -f >actual &&
        test_cmp expect actual
 '
@@ -333,7 +331,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
                git update-index --fsmonitor &&
                GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-before" \
                git status &&
-               test-dump-untracked-cache >../before
+               test-tool dump-untracked-cache >../before
        ) &&
        cat >>dot-git/.git/hooks/fsmonitor-test <<-\EOF &&
        printf ".git\0"
@@ -345,7 +343,7 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
                cd dot-git &&
                GIT_TRACE_UNTRACKED_STATS="$TRASH_DIRECTORY/trace-after" \
                git status &&
-               test-dump-untracked-cache >../after
+               test-tool dump-untracked-cache >../after
        ) &&
        grep "directory invalidation" trace-before >>before &&
        grep "directory invalidation" trace-after >>after &&
@@ -353,4 +351,31 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
        test_cmp before after
 '
 
+test_expect_success 'discard_index() also discards fsmonitor info' '
+       test_config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-all" &&
+       test_might_fail git update-index --refresh &&
+       test-tool read-cache --print-and-refresh=tracked 2 >actual &&
+       printf "tracked is%s up to date\n" "" " not" >expect &&
+       test_cmp expect actual
+'
+
+# Test unstaging entries that:
+#  - Are not flagged with CE_FSMONITOR_VALID
+#  - Have a position in the index >= the number of entries present in the index
+#    after unstaging.
+test_expect_success 'status succeeds after staging/unstaging' '
+       test_create_repo fsmonitor-stage-unstage &&
+       (
+               cd fsmonitor-stage-unstage &&
+               test_commit initial &&
+               git update-index --fsmonitor &&
+               removed=$(test_seq 1 100 | sed "s/^/z/") &&
+               touch $removed &&
+               git add $removed &&
+               git config core.fsmonitor "$TEST_DIRECTORY/t7519/fsmonitor-env" &&
+               FSMONITOR_LIST="$removed" git restore -S $removed &&
+               FSMONITOR_LIST="$removed" git status
+       )
+'
+
 test_done