diff mbox series

[v2,02/14] t1092: behavior for adding sparse files

Message ID 61c23dc59a6e062e073ba3bea135c370a78415aa.1631453010.git.gitgitgadget@gmail.com (mailing list archive)
State New, archived
Headers show
Series Sparse-checkout: modify 'git add', 'git rm', and 'git add' behavior | expand

Commit Message

Derrick Stolee Sept. 12, 2021, 1:23 p.m. UTC
From: Derrick Stolee <dstolee@microsoft.com>

Add some tests to demonstrate the current behavior around adding files
outside of the sparse-checkout cone. Currently, untracked files are
handled differently from tracked files. A future change will make these
cases be handled the same way.

Further expand checking that a failed 'git add' does not stage changes
to the index.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
---
 t/t1092-sparse-checkout-compatibility.sh | 28 ++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Ævar Arnfjörð Bjarmason Sept. 12, 2021, 10:17 p.m. UTC | #1
On Sun, Sep 12 2021, Derrick Stolee via GitGitGadget wrote:

> +# NEEDSWORK: This documents current behavior, but is not a desirable
> +# behavior (untracked files are handled differently than tracked).

I wonder if a test_expect_failure test would be better for the thing
that is the desired behavior, but maybe we don't know what the CLI UI
for that would look like yet.


> +test_expect_success 'add outside sparse cone' '
> +	init_repos &&
> +
> +	run_on_sparse mkdir folder1 &&
> +	run_on_sparse ../edit-contents folder1/a &&
> +	run_on_sparse ../edit-contents folder1/newfile &&
> +	test_sparse_match test_must_fail git add folder1/a &&
> +	test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err &&

Just "grep" is preferred over "test_i18ngrep" now, the GETTEXT_POISON
went away.
Derrick Stolee Sept. 13, 2021, 3:02 p.m. UTC | #2
On 9/12/2021 6:17 PM, Ævar Arnfjörð Bjarmason wrote:
> 
> On Sun, Sep 12 2021, Derrick Stolee via GitGitGadget wrote:
> 
>> +# NEEDSWORK: This documents current behavior, but is not a desirable
>> +# behavior (untracked files are handled differently than tracked).
> 
> I wonder if a test_expect_failure test would be better for the thing
> that is the desired behavior, but maybe we don't know what the CLI UI
> for that would look like yet.

The problem with test_expect_failure is that you don't know which
line of the test is the problem. That's probably all fine and good
when we completely understand the situation we want to solve but
don't have a good approach to fixing it, but here I want to document
a change in behavior.

Using test_expect_success allows me to demonstrate "it works this
way now" and then "this is how behavior changes".

>> +test_expect_success 'add outside sparse cone' '
>> +	init_repos &&
>> +
>> +	run_on_sparse mkdir folder1 &&
>> +	run_on_sparse ../edit-contents folder1/a &&
>> +	run_on_sparse ../edit-contents folder1/newfile &&
>> +	test_sparse_match test_must_fail git add folder1/a &&
>> +	test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err &&
> 
> Just "grep" is preferred over "test_i18ngrep" now, the GETTEXT_POISON
> went away.

Right. Force of habit.

Thanks,
-Stolee
diff mbox series

Patch

diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh
index 886e78715fe..5b3f55e355e 100755
--- a/t/t1092-sparse-checkout-compatibility.sh
+++ b/t/t1092-sparse-checkout-compatibility.sh
@@ -187,6 +187,16 @@  test_sparse_match () {
 	test_cmp sparse-checkout-err sparse-index-err
 }
 
+test_sparse_unstaged () {
+	file=$1 &&
+	for repo in sparse-checkout sparse-index
+	do
+		git -C $repo status --porcelain >$repo-out &&
+		! grep "^A  $file\$" $repo-out &&
+		! grep "^M  $file\$" $repo-out || return 1
+	done
+}
+
 test_expect_success 'sparse-index contents' '
 	init_repos &&
 
@@ -291,6 +301,20 @@  test_expect_success 'add, commit, checkout' '
 	test_all_match git checkout -
 '
 
+# NEEDSWORK: This documents current behavior, but is not a desirable
+# behavior (untracked files are handled differently than tracked).
+test_expect_success 'add outside sparse cone' '
+	init_repos &&
+
+	run_on_sparse mkdir folder1 &&
+	run_on_sparse ../edit-contents folder1/a &&
+	run_on_sparse ../edit-contents folder1/newfile &&
+	test_sparse_match test_must_fail git add folder1/a &&
+	test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err &&
+	test_sparse_unstaged folder1/a &&
+	test_sparse_match git add folder1/newfile
+'
+
 test_expect_success 'commit including unstaged changes' '
 	init_repos &&
 
@@ -339,7 +363,11 @@  test_expect_success 'status/add: outside sparse cone' '
 
 	# Adding the path outside of the sparse-checkout cone should fail.
 	test_sparse_match test_must_fail git add folder1/a &&
+	test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err &&
+	test_sparse_unstaged folder1/a &&
 	test_sparse_match test_must_fail git add --refresh folder1/a &&
+	test_i18ngrep "Disable or modify the sparsity rules" sparse-checkout-err &&
+	test_sparse_unstaged folder1/a &&
 
 	# NEEDSWORK: Adding a newly-tracked file outside the cone succeeds
 	test_sparse_match git add folder1/new &&