diff mbox series

[v2,3/7] reset: expand test coverage for sparse checkouts

Message ID c7e9d9f4e03fe0dbd8a112460f0ac0864f087c8f.1633440057.git.gitgitgadget@gmail.com (mailing list archive)
State Superseded
Headers show
Series Sparse Index: integrate with reset | expand

Commit Message

Victoria Dye Oct. 5, 2021, 1:20 p.m. UTC
From: Victoria Dye <vdye@github.com>

Add new tests for `--merge` and `--keep` modes, as well as mixed reset with
pathspecs both inside and outside of the sparse checkout definition. New
performance test cases exercise various execution paths for `reset`.

Co-authored-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Victoria Dye <vdye@github.com>
---
 t/perf/p2000-sparse-operations.sh        |   3 +
 t/t1092-sparse-checkout-compatibility.sh | 107 +++++++++++++++++++++++
 2 files changed, 110 insertions(+)

Comments

Elijah Newren Oct. 6, 2021, 2:04 a.m. UTC | #1
On Tue, Oct 5, 2021 at 6:21 AM Victoria Dye via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Victoria Dye <vdye@github.com>
>
> Add new tests for `--merge` and `--keep` modes, as well as mixed reset with
> pathspecs both inside and outside of the sparse checkout definition. New
> performance test cases exercise various execution paths for `reset`.
>
> Co-authored-by: Derrick Stolee <dstolee@microsoft.com>
> Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
> Signed-off-by: Victoria Dye <vdye@github.com>
> ---
>  t/perf/p2000-sparse-operations.sh        |   3 +
>  t/t1092-sparse-checkout-compatibility.sh | 107 +++++++++++++++++++++++
>  2 files changed, 110 insertions(+)
>
> diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
> index 597626276fb..bfd332120c8 100755
> --- a/t/perf/p2000-sparse-operations.sh
> +++ b/t/perf/p2000-sparse-operations.sh
> @@ -110,5 +110,8 @@ test_perf_on_all git add -A
>  test_perf_on_all git add .
>  test_perf_on_all git commit -a -m A
>  test_perf_on_all git checkout -f -
> +test_perf_on_all git reset
> +test_perf_on_all git reset --hard
> +test_perf_on_all git reset -- does-not-exist
>
>  test_done
> diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
> index b3c0d3b98ee..f0723a6ac97 100755
> --- a/t/t1092-sparse-checkout-compatibility.sh
> +++ b/t/t1092-sparse-checkout-compatibility.sh
> @@ -479,6 +479,113 @@ test_expect_success 'checkout and reset (mixed) [sparse]' '
>         test_sparse_match git reset update-folder2
>  '
>
> +# 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.

Yeah, I think this comment highlights some of the reasons that writing
the file to the working directory for those files isn't the way I'd
prefer to resolve the inconsistency between the skip-worktree bit and
the presence of the file in the working directory.

> +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 pathspec match in sparse directory' '
> +       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 &&
>
> --
> gitgitgadget
>
diff mbox series

Patch

diff --git a/t/perf/p2000-sparse-operations.sh b/t/perf/p2000-sparse-operations.sh
index 597626276fb..bfd332120c8 100755
--- a/t/perf/p2000-sparse-operations.sh
+++ b/t/perf/p2000-sparse-operations.sh
@@ -110,5 +110,8 @@  test_perf_on_all git add -A
 test_perf_on_all git add .
 test_perf_on_all git commit -a -m A
 test_perf_on_all git checkout -f -
+test_perf_on_all git reset
+test_perf_on_all git reset --hard
+test_perf_on_all git reset -- does-not-exist
 
 test_done
diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index b3c0d3b98ee..f0723a6ac97 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -479,6 +479,113 @@  test_expect_success 'checkout and reset (mixed) [sparse]' '
 	test_sparse_match git reset update-folder2
 '
 
+# 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 pathspec match in sparse directory' '
+	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 &&