t1092: add tests for `git-rm`

Add tests for `git-rm`, make sure it behaves as expected when <pathspec> is both inside or outside of sparse-checkout definition. Helped-by: Victoria Dye <vdye@github.com> Helped-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shaoxuan Yuan committed Aug 7, 2022 at 12:13 UTC ba808251aa9463ac192000316304a348e5eabfbe
1 file changed +57
t/t1092-sparse-checkout-compatibility.sh
+57
@@ -1878,4 +1878,61 @@ test_expect_success 'mv directory from out-of-cone to in-cone' '
1878 grep -e "H deep/0/1" actual
1879 '
1880
1881 +test_expect_success 'rm pathspec inside sparse definition' '
1882 + init_repos &&
1883 +
1884 + test_all_match git rm deep/a &&
1885 + test_all_match git status --porcelain=v2 &&
1886 +
1887 + # test wildcard
1888 + run_on_all git reset --hard &&
1889 + test_all_match git rm deep/* &&
1890 + test_all_match git status --porcelain=v2 &&
1891 +
1892 + # test recursive rm
1893 + run_on_all git reset --hard &&
1894 + test_all_match git rm -r deep &&
1895 + test_all_match git status --porcelain=v2
1896 +'
1897 +
1898 +test_expect_failure 'rm pathspec outside sparse definition' '
1899 + init_repos &&
1900 +
1901 + for file in folder1/a folder1/0/1
1902 + do
1903 + test_sparse_match test_must_fail git rm $file &&
1904 + test_sparse_match test_must_fail git rm --cached $file &&
1905 + test_sparse_match git rm --sparse $file &&
1906 + test_sparse_match git status --porcelain=v2
1907 + done &&
1908 +
1909 + cat >folder1-full <<-EOF &&
1910 + rm ${SQ}folder1/0/0/0${SQ}
1911 + rm ${SQ}folder1/0/1${SQ}
1912 + rm ${SQ}folder1/a${SQ}
1913 + EOF
1914 +
1915 + cat >folder1-sparse <<-EOF &&
1916 + rm ${SQ}folder1/${SQ}
1917 + EOF
1918 +
1919 + # test wildcard
1920 + run_on_sparse git reset --hard &&
1921 + run_on_sparse git sparse-checkout reapply &&
1922 + test_sparse_match test_must_fail git rm folder1/* &&
1923 + run_on_sparse git rm --sparse folder1/* &&
1924 + test_cmp folder1-full sparse-checkout-out &&
1925 + test_cmp folder1-sparse sparse-index-out &&
1926 + test_sparse_match git status --porcelain=v2 &&
1927 +
1928 + # test recursive rm
1929 + run_on_sparse git reset --hard &&
1930 + run_on_sparse git sparse-checkout reapply &&
1931 + test_sparse_match test_must_fail git rm --sparse folder1 &&
1932 + run_on_sparse git rm --sparse -r folder1 &&
1933 + test_cmp folder1-full sparse-checkout-out &&
1934 + test_cmp folder1-sparse sparse-index-out &&
1935 + test_sparse_match git status --porcelain=v2
1936 +'
1937 +
1938 test_done