Skip to content

Commit

Permalink
Merge pull request microsoft#417 from vdye/sparse-index/git-reset
Browse files Browse the repository at this point in the history
Sparse index: `git reset`
  • Loading branch information
vdye authored and ldennington committed Jan 12, 2022
2 parents f0425ae + 85540db commit ba36888
Showing 1 changed file with 107 additions and 0 deletions.
107 changes: 107 additions & 0 deletions t/t1092-sparse-checkout-compatibility.sh
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,113 @@ test_expect_success 'reset with wildcard pathspec' '
test_all_match git ls-files -s -- folder1
'

# NEEDSWORK: with mixed reset, files with differences between HEAD and <commit>
# will be added to the work tree even if outside the sparse checkout
# definition, and even if the file is modified to a state of having no local
# changes. The file is "re-ignored" if a hard reset is executed. We may want to
# change this behavior in the future and enforce that files are not written
# outside of the sparse checkout definition.
test_expect_success 'checkout and mixed reset file tracking [sparse]' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset update-folder1 &&
test_all_match git reset update-deep &&
# At this point, there are no changes in the working tree. However,
# folder1/a now exists locally (even though it is outside of the sparse
# paths).
run_on_sparse test_path_exists folder1 &&
run_on_all rm folder1/a &&
test_all_match git status --porcelain=v2 &&
test_all_match git reset --hard update-deep &&
run_on_sparse test_path_is_missing folder1 &&
test_path_exists full-checkout/folder1
'

test_expect_success 'checkout and reset (merge)' '
init_repos &&
write_script edit-contents <<-\EOF &&
echo text >>$1
EOF
test_all_match git checkout -b reset-test update-deep &&
run_on_all ../edit-contents a &&
test_all_match git reset --merge deepest &&
test_all_match git status --porcelain=v2 &&
test_all_match git reset --hard update-deep &&
run_on_all ../edit-contents deep/a &&
test_all_match test_must_fail git reset --merge deepest
'

test_expect_success 'checkout and reset (keep)' '
init_repos &&
write_script edit-contents <<-\EOF &&
echo text >>$1
EOF
test_all_match git checkout -b reset-test update-deep &&
run_on_all ../edit-contents a &&
test_all_match git reset --keep deepest &&
test_all_match git status --porcelain=v2 &&
test_all_match git reset --hard update-deep &&
run_on_all ../edit-contents deep/a &&
test_all_match test_must_fail git reset --keep deepest
'

test_expect_success 'reset with pathspecs inside sparse definition' '
init_repos &&
write_script edit-contents <<-\EOF &&
echo text >>$1
EOF
test_all_match git checkout -b reset-test update-deep &&
run_on_all ../edit-contents deep/a &&
test_all_match git reset base -- deep/a &&
test_all_match git status --porcelain=v2 &&
test_all_match git reset base -- nonexistent-file &&
test_all_match git status --porcelain=v2 &&
test_all_match git reset deepest -- deep &&
test_all_match git status --porcelain=v2
'

test_expect_success 'reset with sparse directory pathspec outside definition' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset --hard update-folder1 &&
test_all_match git reset base -- folder1 &&
test_all_match git status --porcelain=v2
'

test_expect_success 'reset with file pathspec outside sparse definition' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset --hard update-folder1 &&
test_all_match git reset base -- folder1/a &&
test_all_match git status --porcelain=v2
'

test_expect_success 'reset with wildcard pathspec' '
init_repos &&
test_all_match git checkout -b reset-test update-deep &&
test_all_match git reset --hard update-folder1 &&
test_all_match git reset base -- \*/a &&
test_all_match git status --porcelain=v2
'

test_expect_success 'merge, cherry-pick, and rebase' '
init_repos &&
Expand Down

0 comments on commit ba36888

Please sign in to comment.