[PATCH 05/12] tests for sparse checkout, index protection

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 t/t2300-sparse-index.sh                 |  156 +++++++++++++++++++++
 t/t2300/diff-index-sub.expected         |    3 +
 t/t2300/log.expected                    |   64 +++++++++
 t/t2301-sparse-index-merge-recursive.sh |  226 +++++++++++++++++++++++++++++++
 4 files changed, 449 insertions(+), 0 deletions(-)
 create mode 100755 t/t2300-sparse-index.sh
 create mode 100644 t/t2300/diff-index-sub.expected
 create mode 100644 t/t2300/log.expected
 create mode 100755 t/t2301-sparse-index-merge-recursive.sh

diff --git a/t/t2300-sparse-index.sh b/t/t2300-sparse-index.sh
new file mode 100755
index 0000000..8b9d61f
--- /dev/null
+++ b/t/t2300-sparse-index.sh
@@ -0,0 +1,156 @@
+#!/bin/sh
+
+test_description='sparse checkout -- index update
+
+This test makes sure all commands that touch index will not
+be able to write outside sparse prefix, once set.
+
+It also makes sure some full index operation like git-checkout
+or git-read-tree can function even with index prefix set.
+'
+
+. ./test-lib.sh
+
+setup_repo() {
+	test "$#" = 1 ||
+	error 'bug in the test script: not 1 parameter to setup_repo'
+	test_create_repo "$1" &&
+	(
+		cd "$1" &&
+		mkdir -p work/sub/dir &&
+		touch untracked tracked modified added &&
+		touch work/untracked work/tracked work/modified work/added &&
+		git add tracked work/tracked &&
+		git add modified work/modified &&
+		git commit -m initial &&
+		git add added work/added &&
+		echo modified > modified &&
+		echo work/modified > work/modified
+	)
+}
+
+# this prevent sparse checkout's worktree protection
+# so you can access everything in worktree
+# index modification is limited though
+export GIT_SPARSE_CHECKOUT_INDEX_ONLY=1
+
+test_expect_success 'setup update-index and --show-parse-prefix' '
+	setup_repo update-index &&
+	cd update-index &&
+	git config core.sparsecheckout work:nonwork &&
+	test nonwork:work = "$(git rev-parse --show-sparse-prefix)" &&
+	git config core.sparsecheckout work &&
+	test work = "$(git rev-parse --show-sparse-prefix)"
+'
+
+test_expect_success 'ls-files --with-tree does not bail out' '
+	git ls-files --with-tree=HEAD
+'
+
+test_expect_success 'update-index --refresh with new mtime outside index prefix' '
+	touch tracked &&
+	test -z "$(git update-index --refresh 2>&1 >/dev/null)"
+'
+
+test_expect_success 'update inside' 'git update-index work/modified'
+test_expect_success 'remove inside' 'git update-index --force-remove work/tracked'
+test_expect_success 'add inside' 'git update-index --add work/untracked'
+
+test_expect_success 'update outside' '! git update-index modified'
+test_expect_success 'remove outside' '! git update-index --force-remove modified'
+test_expect_success 'add outside' '! git update-index --add untracked'
+
+test_expect_success 'setup add' '
+	cd .. &&
+	setup_repo add &&
+	cd add
+	git config core.sparsecheckout work &&
+	test work = "$(git rev-parse --show-sparse-prefix)"
+'
+
+test_expect_success 'add inside' 'git add work/modified'
+test_expect_success 'add outside' '! git add untracked'
+
+test_expect_success 'setup rm' '
+	cd .. &&
+	setup_repo rm &&
+	cd rm &&
+	git config core.sparsecheckout work
+	test work = "$(git rev-parse --show-sparse-prefix)"
+'
+
+test_expect_success 'inside:  rm' 'git rm work/tracked'
+test_expect_success 'outside:  rm' '! git rm tracked'
+
+test_expect_success 'setup apply' '
+	cd .. &&
+	test_create_repo apply &&
+	cd apply &&
+	mkdir -p work/sub/dir &&
+	touch modified work/modified &&
+	git add modified work/modified &&
+	git config core.sparsecheckout work &&
+	test work = "$(git rev-parse --show-sparse-prefix)"
+'
+
+cat <<EOF > outside.patch
+diff --git a/modified b/modified
+index e69de29..2e09960 100644
+--- a/modified
++++ b/modified
+@@ -0,0 +1 @@
++modified
+EOF
+
+cat <<EOF > inside.patch
+diff --git a/work/modified b/work/modified
+index e69de29..4bd2893 100644
+--- a/work/modified
++++ b/work/modified
+@@ -0,0 +1 @@
++work/modified
+EOF
+
+
+test_expect_success 'inside:  apply --cached' 'git apply --cached inside.patch'
+test_expect_success 'outside:  apply --cached' '! git apply --cached outside.patch'
+
+test_expect_success 'setup read-tree (clean worktree)' '
+	cd ..
+	test_create_repo read-tree &&
+	cd read-tree &&
+	test_tick &&
+	mkdir -p work/sub/dir &&
+	echo one > one && git add one && git commit -m one &&
+	echo two >> one && git add one && git commit -m two &&
+	echo one > work/one && git add work/one && git commit -m work/one &&
+	echo two >> work/one && git add work/one && git commit -m work/two &&
+	echo one > work/sub/one && git add work/sub/one && git commit -m work/sub/one &&
+	echo two >> work/sub/one && git add work/sub/one && git commit -m work/sub/two &&
+	echo one > work/sub/dir/one && echo three >> work/one &&
+		git add work/sub/dir/one work/one &&
+		git commit -m work/sub/dir/one &&
+	echo two >> work/sub/dir/one &&
+		git add work/sub/dir/one &&
+		git commit -m work/sub/dir/two &&
+	git log --raw > ../log.result &&
+	cmp ../../t2300/log.expected ../log.result &&
+	git config core.sparsecheckout work/sub &&
+	test work/sub = "$(git rev-parse --show-sparse-prefix)"
+'
+
+test_expect_success 'read-tree inside index prefix' '
+	git read-tree 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d &&
+	test -z "$(git diff-index --cached 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d)"'
+
+test_expect_success 'read-tree outside index prefix' '
+	! git read-tree b64ae04f6be47b3d729f731de1ce804223f45113'
+
+test_expect_success 'read-tree with --prefix outside' '
+	! git read-tree --prefix=work/newsub/ b64ae04f6be47b3d729f731de1ce804223f45113'
+
+test_expect_success 'read-tree with --prefix inside' '
+	git read-tree --prefix=work/sub/dir/newsub/ b64ae04f6be47b3d729f731de1ce804223f45113 &&
+	git diff-index --cached 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d|cmp ../../t2300/diff-index-sub.expected'
+
+test_done
diff --git a/t/t2300/diff-index-sub.expected b/t/t2300/diff-index-sub.expected
new file mode 100644
index 0000000..49b1a47
--- /dev/null
+++ b/t/t2300/diff-index-sub.expected
@@ -0,0 +1,3 @@
+:000000 100644 0000000000000000000000000000000000000000 814f4a422927b82f5f8a43f8fab6d3839e3983f2 A	work/sub/dir/newsub/one
+:000000 100644 0000000000000000000000000000000000000000 814f4a422927b82f5f8a43f8fab6d3839e3983f2 A	work/sub/dir/newsub/work/one
+:000000 100644 0000000000000000000000000000000000000000 5626abf0f72e58d7a153368ba57db4c673c0e171 A	work/sub/dir/newsub/work/sub/one
diff --git a/t/t2300/log.expected b/t/t2300/log.expected
new file mode 100644
index 0000000..58b69bd
--- /dev/null
+++ b/t/t2300/log.expected
@@ -0,0 +1,64 @@
+commit 69798ebb265c266292b4919f7a943bc30d72dfa3
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/sub/dir/two
+
+:100644 100644 5626abf... 814f4a4... M	work/sub/dir/one
+
+commit 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/sub/dir/one
+
+:100644 100644 814f4a4... 4cb29ea... M	work/one
+:000000 100644 0000000... 5626abf... A	work/sub/dir/one
+
+commit dd5fc8b46ac73c49bb046e16b0d9980a8142de51
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/sub/two
+
+:100644 100644 5626abf... 814f4a4... M	work/sub/one
+
+commit b64ae04f6be47b3d729f731de1ce804223f45113
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/sub/one
+
+:000000 100644 0000000... 5626abf... A	work/sub/one
+
+commit 69da5948890ae9caff70388451ba5ede78b77d08
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/two
+
+:100644 100644 5626abf... 814f4a4... M	work/one
+
+commit e63957619e33be2985dacdbb077f4c2ca7210319
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    work/one
+
+:000000 100644 0000000... 5626abf... A	work/one
+
+commit e6742a1800d08c749ebbc01d1f4ca03b66ff44e1
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    two
+
+:100644 100644 5626abf... 814f4a4... M	one
+
+commit 1c60dc5aa63dc2956ceb3ccc399d04245bc2cc1b
+Author: A U Thor <author@xxxxxxxxxxx>
+Date:   Thu Apr 7 15:13:13 2005 -0700
+
+    one
+
+:000000 100644 0000000... 5626abf... A	one
diff --git a/t/t2301-sparse-index-merge-recursive.sh b/t/t2301-sparse-index-merge-recursive.sh
new file mode 100755
index 0000000..61b3766
--- /dev/null
+++ b/t/t2301-sparse-index-merge-recursive.sh
@@ -0,0 +1,226 @@
+#!/bin/sh
+
+test_description='merge-recursive backend test'
+
+. ./test-lib.sh
+
+# this prevent sparse checkout's worktree protection
+# so you can access everything in worktree
+# index modification is limited though
+export GIT_SPARSE_CHECKOUT_INDEX_ONLY=1
+
+test_expect_success 'setup 1' '
+
+	echo hello >a &&
+	o0=$(git hash-object a) &&
+	cp a b &&
+	cp a c &&
+	mkdir d &&
+	cp a d/e &&
+
+	test_tick &&
+	git add a b c d/e &&
+	git commit -m initial &&
+	c0=$(git rev-parse --verify HEAD) &&
+	git branch noconflict &&
+	git branch conflict &&
+	git branch conflict-inside &&
+
+	echo hello >>a &&
+	cp a d/e &&
+	o1=$(git hash-object a) &&
+
+	git add a d/e &&
+
+	test_tick &&
+	git commit -m "master modifies a and d/e" &&
+	c1=$(git rev-parse --verify HEAD) &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o1	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o1	d/e"
+		echo "100644 $o1 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o1 0	d/e"
+	) >expected &&
+	test_cmp expected actual
+'
+
+test_expect_success 'setup 2' '
+
+	rm -rf [abcd] &&
+	git checkout conflict &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o0	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o0	d/e"
+		echo "100644 $o0 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o0 0	d/e"
+	) >expected &&
+	test_cmp expected actual &&
+
+	echo goodbye >>a &&
+	o2=$(git hash-object a) &&
+
+	git add a &&
+
+	test_tick &&
+	git commit -m "conflict modifies a" &&
+	c2=$(git rev-parse --verify HEAD) &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o2	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o0	d/e"
+		echo "100644 $o2 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o0 0	d/e"
+	) >expected &&
+	test_cmp expected actual
+'
+
+test_expect_success 'setup 3' '
+
+	rm -rf [abcd] &&
+	git checkout noconflict &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o0	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o0	d/e"
+		echo "100644 $o0 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o0 0	d/e"
+	) >expected &&
+	test_cmp expected actual &&
+
+	echo hello >>a &&
+	o3=$(git hash-object a) &&
+
+	git add a &&
+
+	test_tick &&
+	git commit -m "noconflict modifies a" &&
+	c3=$(git rev-parse --verify HEAD) &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o3	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o0	d/e"
+		echo "100644 $o3 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o0 0	d/e"
+	) >expected &&
+	test_cmp expected actual
+'
+
+test_expect_success 'setup 4' '
+
+	rm -rf [abcd] &&
+	git checkout conflict-inside &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o0	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o0	d/e"
+		echo "100644 $o0 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o0 0	d/e"
+	) >expected &&
+	test_cmp expected actual &&
+
+	mkdir d &&
+	echo goodbye >>d/e &&
+	o4=$(git hash-object d/e) &&
+
+	git add d/e &&
+
+	test_tick &&
+	git commit -m "conflict-inside modifies d/e" &&
+	c4=$(git rev-parse --verify HEAD) &&
+	( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
+	(
+		echo "100644 blob $o0	a"
+		echo "100644 blob $o0	b"
+		echo "100644 blob $o0	c"
+		echo "100644 blob $o4	d/e"
+		echo "100644 $o0 0	a"
+		echo "100644 $o0 0	b"
+		echo "100644 $o0 0	c"
+		echo "100644 $o4 0	d/e"
+	) >expected &&
+	test_cmp expected actual
+'
+
+export GIT_INDEX_PREFIX=d/
+
+test_expect_success 'merge-recursive conflict inside' '
+
+	rm -fr [abcd] &&
+	git checkout -f "$c4" &&
+
+	git-merge-recursive "$c0" -- "$c4" "$c1"
+	status=$?
+	case "$status" in
+	1)
+		: happy
+		;;
+	*)
+		echo >&2 "why status $status!!!"
+		false
+		;;
+	esac
+'
+
+test_expect_success 'merge-recursive no conflict outside' '
+
+	rm -fr [abcd] &&
+	git checkout -f "$c3" &&
+
+	git-merge-recursive "$c0" -- "$c3" "$c1"
+	status=$?
+	case "$status" in
+	0)
+		: happy
+		;;
+	*)
+		echo >&2 "why status $status!!!"
+		false
+		;;
+	esac
+'
+
+test_expect_success 'merge-recursive conflict outside' '
+
+	rm -fr [abcd] &&
+	git checkout -f "$c2" &&
+
+	git-merge-recursive "$c0" -- "$c2" "$c1"
+	status=$?
+	case "$status" in
+	1)
+		: happy
+		;;
+	*)
+		echo >&2 "why status $status!!!"
+		false
+		;;
+	esac
+'
+
+test_done
-- 
1.5.5.GIT
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux