diff mbox series

[v4,3/3] t4140: test apply with i-t-a paths

Message ID 20200806060119.74587-4-ray@ameretat.dev (mailing list archive)
State Superseded
Headers show
Series apply: handle i-t-a entries in index | expand

Commit Message

Raymond E. Pasco Aug. 6, 2020, 6:01 a.m. UTC
apply --cached (as used by add -p) should accept creation and deletion
patches to intent-to-add paths in the index. apply --index, however,
should always fail because an intent-to-add path never matches the
worktree (by definition).

Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Raymond E. Pasco <ray@ameretat.dev>
---
 t/t4140-apply-ita.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 t/t4140-apply-ita.sh

Comments

Junio C Hamano Aug. 6, 2020, 9:07 p.m. UTC | #1
"Raymond E. Pasco" <ray@ameretat.dev> writes:

> apply --cached (as used by add -p) should accept creation and deletion
> patches to intent-to-add paths in the index. apply --index, however,
> should always fail because an intent-to-add path never matches the
> worktree (by definition).
>
> Based-on-patch-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Raymond E. Pasco <ray@ameretat.dev>
> ---
>  t/t4140-apply-ita.sh | 56 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 56 insertions(+)
>  create mode 100644 t/t4140-apply-ita.sh

chmod +x

> diff --git a/t/t4140-apply-ita.sh b/t/t4140-apply-ita.sh
> new file mode 100644
> index 0000000000..c614eaf04c
> --- /dev/null
> +++ b/t/t4140-apply-ita.sh
> @@ -0,0 +1,56 @@
> +#!/bin/sh
> +
> +test_description='git apply of i-t-a file'
> +
> +. ./test-lib.sh
> +
> +test_expect_success setup '
> +	test_write_lines 1 2 3 4 5 >blueprint &&
> +
> +	cat blueprint >test-file &&
> +	git add -N test-file &&
> +	git diff >creation-patch &&
> +	grep "new file mode 100644" creation-patch &&
> +
> +	rm -f test-file &&
> +	git diff >deletion-patch &&
> +	grep "deleted file mode 100644" deletion-patch
> +'
> +
> +test_expect_success 'apply creation patch to ita path (--cached)' '
> +	git rm -f test-file &&
> +	cat blueprint >test-file &&
> +	git add -N test-file &&
> +
> +	git apply --cached creation-patch &&
> +	git cat-file blob :test-file >actual &&
> +	test_cmp blueprint actual
> +'

OK, this is a good positive test case.

> +test_expect_success 'apply creation patch to ita path (--index)' '
> +	git rm -f test-file &&
> +	cat blueprint >test-file &&
> +	git add -N test-file &&
> +	rm -f test-file &&
> +
> +	test_must_fail git apply --index creation-patch
> +'

"--index" (not "--cached") notices that test-file does not match
between the index and the working tree, and fails.  OK.

> +test_expect_success 'apply deletion patch to ita path (--cached)' '
> +	git rm -f test-file &&
> +	cat blueprint >test-file &&
> +	git add -N test-file &&
> +
> +	git apply --cached deletion-patch &&
> +	test_must_fail git ls-files --stage --error-unmatch test-file
> +'

We can delete an I-T-A entry.  I wonder if

	git apply --cached -R creation-patch

also serves as a way to remove the path?  It should succeed, right?

> +test_expect_success 'apply deletion patch to ita path (--index)' '
> +	cat blueprint >test-file &&
> +	git add -N test-file &&
> +
> +	test_must_fail git apply --index deletion-patch &&
> +	git ls-files --stage --error-unmatch test-file
> +'

Again "--index" notices that the path has ITA bit on, and refuses to
remove it.

OK, looking good so far.

Thanks.
Raymond E. Pasco Aug. 7, 2020, 3:44 a.m. UTC | #2
On Thu Aug 6, 2020 at 5:07 PM EDT, Junio C Hamano wrote:
> We can delete an I-T-A entry. I wonder if
>
> git apply --cached -R creation-patch
>
> also serves as a way to remove the path? It should succeed, right?

It fails to apply because the inverse patch to creation-patch removes
lines, while the i-t-a entry has no lines. (Looking at it from the other
angle, deletion-patch doesn't delete lines, because there are none.)

(Of course, -R creation-patch after creation-patch removes the path
cleanly.)
diff mbox series

Patch

diff --git a/t/t4140-apply-ita.sh b/t/t4140-apply-ita.sh
new file mode 100644
index 0000000000..c614eaf04c
--- /dev/null
+++ b/t/t4140-apply-ita.sh
@@ -0,0 +1,56 @@ 
+#!/bin/sh
+
+test_description='git apply of i-t-a file'
+
+. ./test-lib.sh
+
+test_expect_success setup '
+	test_write_lines 1 2 3 4 5 >blueprint &&
+
+	cat blueprint >test-file &&
+	git add -N test-file &&
+	git diff >creation-patch &&
+	grep "new file mode 100644" creation-patch &&
+
+	rm -f test-file &&
+	git diff >deletion-patch &&
+	grep "deleted file mode 100644" deletion-patch
+'
+
+test_expect_success 'apply creation patch to ita path (--cached)' '
+	git rm -f test-file &&
+	cat blueprint >test-file &&
+	git add -N test-file &&
+
+	git apply --cached creation-patch &&
+	git cat-file blob :test-file >actual &&
+	test_cmp blueprint actual
+'
+
+test_expect_success 'apply creation patch to ita path (--index)' '
+	git rm -f test-file &&
+	cat blueprint >test-file &&
+	git add -N test-file &&
+	rm -f test-file &&
+
+	test_must_fail git apply --index creation-patch
+'
+
+test_expect_success 'apply deletion patch to ita path (--cached)' '
+	git rm -f test-file &&
+	cat blueprint >test-file &&
+	git add -N test-file &&
+
+	git apply --cached deletion-patch &&
+	test_must_fail git ls-files --stage --error-unmatch test-file
+'
+
+test_expect_success 'apply deletion patch to ita path (--index)' '
+	cat blueprint >test-file &&
+	git add -N test-file &&
+
+	test_must_fail git apply --index deletion-patch &&
+	git ls-files --stage --error-unmatch test-file
+'
+
+test_done