@@ -2055,4 +2055,65 @@ test_expect_success 'grep sparse directory within submodules' '
2055
2055
test_cmp actual expect
2056
2056
'
2057
2057
2058
+ test_expect_success ' diff-files with pathspec inside sparse definition' '
2059
+ init_repos &&
2060
+
2061
+ write_script edit-contents <<-\EOF &&
2062
+ echo text >>"$1"
2063
+ EOF
2064
+
2065
+ run_on_all ../edit-contents deep/a &&
2066
+
2067
+ test_all_match git diff-files &&
2068
+
2069
+ test_all_match git diff-files deep/a
2070
+
2071
+ '
2072
+
2073
+ test_expect_success ' diff-files with pathspec outside sparse definition' '
2074
+ init_repos &&
2075
+
2076
+ write_script edit-contents <<-\EOF &&
2077
+ echo text >>"$1"
2078
+ EOF
2079
+
2080
+ # add file to the index but outside of cone
2081
+ run_on_sparse mkdir newdirectory &&
2082
+ run_on_sparse ../edit-contents newdirectory/testfile &&
2083
+ test_sparse_match git add --sparse newdirectory/testfile &&
2084
+
2085
+ # file present on-disk without modifications
2086
+ test_sparse_match git diff-files &&
2087
+ test_must_be_empty sparse-checkout-out &&
2088
+ test_must_be_empty sparse-checkout-err &&
2089
+ test_sparse_match git diff-files newdirectory/testfile &&
2090
+ test_must_be_empty sparse-checkout-out &&
2091
+ test_must_be_empty sparse-checkout-err &&
2092
+
2093
+ # file present on-disk with modifications
2094
+ FN=newdirectory/testfile &&
2095
+ OID=$(git -C sparse-checkout hash-object $FN) &&
2096
+ ZERO=$(test_oid zero) &&
2097
+ echo ":100644 100644 $OID $ZERO M $FN" >expect &&
2098
+
2099
+ run_on_sparse ../edit-contents newdirectory/testfile &&
2100
+ test_sparse_match git diff-files &&
2101
+ test_cmp expect sparse-checkout-out &&
2102
+ test_sparse_match git diff-files newdirectory/testfile &&
2103
+ test_cmp expect sparse-checkout-out
2104
+ '
2105
+
2106
+ test_expect_success ' sparse index is not expanded: diff-files' '
2107
+ init_repos &&
2108
+
2109
+ write_script edit-contents <<-\EOF &&
2110
+ echo text >>"$1"
2111
+ EOF
2112
+
2113
+ run_on_all ../edit-contents deep/a &&
2114
+
2115
+ ensure_not_expanded diff-files &&
2116
+ ensure_not_expanded diff-files deep/a
2117
+ '
2118
+
2058
2119
test_done
0 commit comments