[WIP/RFC PATCH 2/2] Add tests for index prefix

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

 



---
 t/t2300-index-prefix.sh                 |  207 +++++++++++++++++++++++++++++
 t/t2301-index-prefix-merge-recursive.sh |  221 +++++++++++++++++++++++++++++++
 2 files changed, 428 insertions(+), 0 deletions(-)
 create mode 100755 t/t2300-index-prefix.sh
 create mode 100755 t/t2301-index-prefix-merge-recursive.sh

diff --git a/t/t2300-index-prefix.sh b/t/t2300-index-prefix.sh
new file mode 100755
index 0000000..a7fa559
--- /dev/null
+++ b/t/t2300-index-prefix.sh
@@ -0,0 +1,207 @@
+#!/bin/sh
+
+test_description='index prefix test
+
+This test makes sure all commands that touch index will not
+be able to write outside index prefix once set.
+
+It also make sure some full index operation like git-checkout
+or git-read-tree can function even with index prefix set.
+'
+. ./test-lib.sh
+#. ../lib-read-tree-m-3way.sh
+
+setup_repo() {
+	test "$#" = 1 ||
+	error 'bug in the test script: not 1 parameter to setup_repo'
+	unset GIT_INDEX_PREFIX &&
+	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
+	)
+}
+
+
+test_expect_success 'setup update-index' 'setup_repo update-index && cd update-index'
+export GIT_INDEX_PREFIX='work/'
+
+test_expect_success 'rev-parse --show-index-prefix' 'test work/ = "$(git rev-parse --show-index-prefix)"'
+test_expect_success 'update-index --refresh with mtime outside index prefix' '
+	touch tracked &&
+	test -z "$(git update-index --refresh 2>&1 >/dev/null)"'
+test_expect_success 'inside:  update' 'git update-index work/modified'
+test_expect_success 'inside:  remove' 'git update-index --force-remove work/tracked'
+test_expect_success 'inside:  add' 'git update-index --add work/untracked'
+test_expect_success 'outside:  update' '! git update-index modified'
+test_expect_success 'outside:  remove' '! git update-index --force-remove modified'
+test_expect_success 'outside:  add' '! git update-index --add untracked'
+
+test_expect_success 'setup add' 'cd .. && setup_repo add && cd add'
+export GIT_INDEX_PREFIX='work/'
+
+test_expect_success 'rev-parse --show-index-prefix' 'test work/ = "$(git rev-parse --show-index-prefix)"'
+test_expect_success 'inside:  add' 'git add work/modified'
+test_expect_success 'outside:  add' '! git add untracked'
+
+test_expect_success 'setup rm' 'cd .. && setup_repo rm && cd rm'
+export GIT_INDEX_PREFIX='work/'
+
+test_expect_success 'rev-parse --show-index-prefix' 'test work/ = "$(git rev-parse --show-index-prefix)"'
+test_expect_success 'inside:  rm' 'git rm work/tracked'
+test_expect_success 'outside:  rm' '! git rm tracked'
+
+test_expect_success 'setup apply' '
+	cd .. &&
+	unset GIT_INDEX_PREFIX &&
+	test_create_repo apply &&
+	cd apply &&
+	mkdir -p work/sub/dir &&
+	touch modified work/modified &&
+	git add modified work/modified'
+export GIT_INDEX_PREFIX='work/'
+
+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 'rev-parse --show-index-prefix' 'test work/ = "$(git rev-parse --show-index-prefix)"'
+test_expect_success 'inside:  apply --cached' 'git apply --cached inside.patch'
+test_expect_success 'outside:  apply --cached' '! git apply --cached outside.patch'
+
+cd ..
+cat >expected-log <<\EOF
+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
+EOF
+READ_TREE_HEAD=69798ebb265c266292b4919f7a943bc30d72dfa3
+export READ_TREE_HEAD
+
+test_expect_success 'setup read-tree (clean worktree)' '
+	unset GIT_INDEX_PREFIX &&
+	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 > ../real-log &&
+	cmp ../expected-log ../real-log &&
+	test $READ_TREE_HEAD = $(git rev-parse HEAD)'
+export GIT_INDEX_PREFIX='work/sub/'
+
+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'
+
+cat >newsub.diff <<\EOF
+: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
+EOF
+test_expect_success 'read-tree with --prefix inside' '
+	git read-tree --prefix=work/sub/dir/newsub/ b64ae04f6be47b3d729f731de1ce804223f45113 &&
+	git diff-index --cached 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d|cmp newsub.diff'
+
+test_done
diff --git a/t/t2301-index-prefix-merge-recursive.sh b/t/t2301-index-prefix-merge-recursive.sh
new file mode 100755
index 0000000..4121878
--- /dev/null
+++ b/t/t2301-index-prefix-merge-recursive.sh
@@ -0,0 +1,221 @@
+#!/bin/sh
+
+test_description='merge-recursive backend test'
+
+. ./test-lib.sh
+
+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
+	128)
+		: 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