{"thread":{"id":"14623","subject":"[PATCH 05/12] tests for sparse checkout, index protection","startedAt":"2008-07-23T14:56:32Z","lastAt":"2008-07-23T14:56:32Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"84511","messageId":"20080723145632.GA29100@laptop","threadId":"14623","inReplyTo":null,"subject":"[PATCH 05/12] tests for sparse checkout, index protection","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-07-23T14:56:32Z","receivedAt":"2008-07-23T14:56:32Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n t/t2300-sparse-index.sh                 |  156 +++++++++++++++++++++\n t/t2300/diff-index-sub.expected         |    3 +\n t/t2300/log.expected                    |   64 +++++++++\n t/t2301-sparse-index-merge-recursive.sh |  226 +++++++++++++++++++++++++++++++\n 4 files changed, 449 insertions(+), 0 deletions(-)\n create mode 100755 t/t2300-sparse-index.sh\n create mode 100644 t/t2300/diff-index-sub.expected\n create mode 100644 t/t2300/log.expected\n create mode 100755 t/t2301-sparse-index-merge-recursive.sh\n\ndiff --git a/t/t2300-sparse-index.sh b/t/t2300-sparse-index.sh\nnew file mode 100755\nindex 0000000..8b9d61f\n--- /dev/null\n+++ b/t/t2300-sparse-index.sh\n@@ -0,0 +1,156 @@\n+#!/bin/sh\n+\n+test_description='sparse checkout -- index update\n+\n+This test makes sure all commands that touch index will not\n+be able to write outside sparse prefix, once set.\n+\n+It also makes sure some full index operation like git-checkout\n+or git-read-tree can function even with index prefix set.\n+'\n+\n+. ./test-lib.sh\n+\n+setup_repo() {\n+\ttest \"$#\" = 1 ||\n+\terror 'bug in the test script: not 1 parameter to setup_repo'\n+\ttest_create_repo \"$1\" &&\n+\t(\n+\t\tcd \"$1\" &&\n+\t\tmkdir -p work/sub/dir &&\n+\t\ttouch untracked tracked modified added &&\n+\t\ttouch work/untracked work/tracked work/modified work/added &&\n+\t\tgit add tracked work/tracked &&\n+\t\tgit add modified work/modified &&\n+\t\tgit commit -m initial &&\n+\t\tgit add added work/added &&\n+\t\techo modified > modified &&\n+\t\techo work/modified > work/modified\n+\t)\n+}\n+\n+# this prevent sparse checkout's worktree protection\n+# so you can access everything in worktree\n+# index modification is limited though\n+export GIT_SPARSE_CHECKOUT_INDEX_ONLY=1\n+\n+test_expect_success 'setup update-index and --show-parse-prefix' '\n+\tsetup_repo update-index &&\n+\tcd update-index &&\n+\tgit config core.sparsecheckout work:nonwork &&\n+\ttest nonwork:work = \"$(git rev-parse --show-sparse-prefix)\" &&\n+\tgit config core.sparsecheckout work &&\n+\ttest work = \"$(git rev-parse --show-sparse-prefix)\"\n+'\n+\n+test_expect_success 'ls-files --with-tree does not bail out' '\n+\tgit ls-files --with-tree=HEAD\n+'\n+\n+test_expect_success 'update-index --refresh with new mtime outside index prefix' '\n+\ttouch tracked &&\n+\ttest -z \"$(git update-index --refresh 2>&1 >/dev/null)\"\n+'\n+\n+test_expect_success 'update inside' 'git update-index work/modified'\n+test_expect_success 'remove inside' 'git update-index --force-remove work/tracked'\n+test_expect_success 'add inside' 'git update-index --add work/untracked'\n+\n+test_expect_success 'update outside' '! git update-index modified'\n+test_expect_success 'remove outside' '! git update-index --force-remove modified'\n+test_expect_success 'add outside' '! git update-index --add untracked'\n+\n+test_expect_success 'setup add' '\n+\tcd .. &&\n+\tsetup_repo add &&\n+\tcd add\n+\tgit config core.sparsecheckout work &&\n+\ttest work = \"$(git rev-parse --show-sparse-prefix)\"\n+'\n+\n+test_expect_success 'add inside' 'git add work/modified'\n+test_expect_success 'add outside' '! git add untracked'\n+\n+test_expect_success 'setup rm' '\n+\tcd .. &&\n+\tsetup_repo rm &&\n+\tcd rm &&\n+\tgit config core.sparsecheckout work\n+\ttest work = \"$(git rev-parse --show-sparse-prefix)\"\n+'\n+\n+test_expect_success 'inside:  rm' 'git rm work/tracked'\n+test_expect_success 'outside:  rm' '! git rm tracked'\n+\n+test_expect_success 'setup apply' '\n+\tcd .. &&\n+\ttest_create_repo apply &&\n+\tcd apply &&\n+\tmkdir -p work/sub/dir &&\n+\ttouch modified work/modified &&\n+\tgit add modified work/modified &&\n+\tgit config core.sparsecheckout work &&\n+\ttest work = \"$(git rev-parse --show-sparse-prefix)\"\n+'\n+\n+cat <<EOF > outside.patch\n+diff --git a/modified b/modified\n+index e69de29..2e09960 100644\n+--- a/modified\n++++ b/modified\n+@@ -0,0 +1 @@\n++modified\n+EOF\n+\n+cat <<EOF > inside.patch\n+diff --git a/work/modified b/work/modified\n+index e69de29..4bd2893 100644\n+--- a/work/modified\n++++ b/work/modified\n+@@ -0,0 +1 @@\n++work/modified\n+EOF\n+\n+\n+test_expect_success 'inside:  apply --cached' 'git apply --cached inside.patch'\n+test_expect_success 'outside:  apply --cached' '! git apply --cached outside.patch'\n+\n+test_expect_success 'setup read-tree (clean worktree)' '\n+\tcd ..\n+\ttest_create_repo read-tree &&\n+\tcd read-tree &&\n+\ttest_tick &&\n+\tmkdir -p work/sub/dir &&\n+\techo one > one && git add one && git commit -m one &&\n+\techo two >> one && git add one && git commit -m two &&\n+\techo one > work/one && git add work/one && git commit -m work/one &&\n+\techo two >> work/one && git add work/one && git commit -m work/two &&\n+\techo one > work/sub/one && git add work/sub/one && git commit -m work/sub/one &&\n+\techo two >> work/sub/one && git add work/sub/one && git commit -m work/sub/two &&\n+\techo one > work/sub/dir/one && echo three >> work/one &&\n+\t\tgit add work/sub/dir/one work/one &&\n+\t\tgit commit -m work/sub/dir/one &&\n+\techo two >> work/sub/dir/one &&\n+\t\tgit add work/sub/dir/one &&\n+\t\tgit commit -m work/sub/dir/two &&\n+\tgit log --raw > ../log.result &&\n+\tcmp ../../t2300/log.expected ../log.result &&\n+\tgit config core.sparsecheckout work/sub &&\n+\ttest work/sub = \"$(git rev-parse --show-sparse-prefix)\"\n+'\n+\n+test_expect_success 'read-tree inside index prefix' '\n+\tgit read-tree 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d &&\n+\ttest -z \"$(git diff-index --cached 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d)\"'\n+\n+test_expect_success 'read-tree outside index prefix' '\n+\t! git read-tree b64ae04f6be47b3d729f731de1ce804223f45113'\n+\n+test_expect_success 'read-tree with --prefix outside' '\n+\t! git read-tree --prefix=work/newsub/ b64ae04f6be47b3d729f731de1ce804223f45113'\n+\n+test_expect_success 'read-tree with --prefix inside' '\n+\tgit read-tree --prefix=work/sub/dir/newsub/ b64ae04f6be47b3d729f731de1ce804223f45113 &&\n+\tgit diff-index --cached 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d|cmp ../../t2300/diff-index-sub.expected'\n+\n+test_done\ndiff --git a/t/t2300/diff-index-sub.expected b/t/t2300/diff-index-sub.expected\nnew file mode 100644\nindex 0000000..49b1a47\n--- /dev/null\n+++ b/t/t2300/diff-index-sub.expected\n@@ -0,0 +1,3 @@\n+:000000 100644 0000000000000000000000000000000000000000 814f4a422927b82f5f8a43f8fab6d3839e3983f2 A\twork/sub/dir/newsub/one\n+:000000 100644 0000000000000000000000000000000000000000 814f4a422927b82f5f8a43f8fab6d3839e3983f2 A\twork/sub/dir/newsub/work/one\n+:000000 100644 0000000000000000000000000000000000000000 5626abf0f72e58d7a153368ba57db4c673c0e171 A\twork/sub/dir/newsub/work/sub/one\ndiff --git a/t/t2300/log.expected b/t/t2300/log.expected\nnew file mode 100644\nindex 0000000..58b69bd\n--- /dev/null\n+++ b/t/t2300/log.expected\n@@ -0,0 +1,64 @@\n+commit 69798ebb265c266292b4919f7a943bc30d72dfa3\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/sub/dir/two\n+\n+:100644 100644 5626abf... 814f4a4... M\twork/sub/dir/one\n+\n+commit 47b2996ef7d1dd7d5fd146c520ed90995e2d7e0d\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/sub/dir/one\n+\n+:100644 100644 814f4a4... 4cb29ea... M\twork/one\n+:000000 100644 0000000... 5626abf... A\twork/sub/dir/one\n+\n+commit dd5fc8b46ac73c49bb046e16b0d9980a8142de51\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/sub/two\n+\n+:100644 100644 5626abf... 814f4a4... M\twork/sub/one\n+\n+commit b64ae04f6be47b3d729f731de1ce804223f45113\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/sub/one\n+\n+:000000 100644 0000000... 5626abf... A\twork/sub/one\n+\n+commit 69da5948890ae9caff70388451ba5ede78b77d08\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/two\n+\n+:100644 100644 5626abf... 814f4a4... M\twork/one\n+\n+commit e63957619e33be2985dacdbb077f4c2ca7210319\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    work/one\n+\n+:000000 100644 0000000... 5626abf... A\twork/one\n+\n+commit e6742a1800d08c749ebbc01d1f4ca03b66ff44e1\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    two\n+\n+:100644 100644 5626abf... 814f4a4... M\tone\n+\n+commit 1c60dc5aa63dc2956ceb3ccc399d04245bc2cc1b\n+Author: A U Thor <author@example.com>\n+Date:   Thu Apr 7 15:13:13 2005 -0700\n+\n+    one\n+\n+:000000 100644 0000000... 5626abf... A\tone\ndiff --git a/t/t2301-sparse-index-merge-recursive.sh b/t/t2301-sparse-index-merge-recursive.sh\nnew file mode 100755\nindex 0000000..61b3766\n--- /dev/null\n+++ b/t/t2301-sparse-index-merge-recursive.sh\n@@ -0,0 +1,226 @@\n+#!/bin/sh\n+\n+test_description='merge-recursive backend test'\n+\n+. ./test-lib.sh\n+\n+# this prevent sparse checkout's worktree protection\n+# so you can access everything in worktree\n+# index modification is limited though\n+export GIT_SPARSE_CHECKOUT_INDEX_ONLY=1\n+\n+test_expect_success 'setup 1' '\n+\n+\techo hello >a &&\n+\to0=$(git hash-object a) &&\n+\tcp a b &&\n+\tcp a c &&\n+\tmkdir d &&\n+\tcp a d/e &&\n+\n+\ttest_tick &&\n+\tgit add a b c d/e &&\n+\tgit commit -m initial &&\n+\tc0=$(git rev-parse --verify HEAD) &&\n+\tgit branch noconflict &&\n+\tgit branch conflict &&\n+\tgit branch conflict-inside &&\n+\n+\techo hello >>a &&\n+\tcp a d/e &&\n+\to1=$(git hash-object a) &&\n+\n+\tgit add a d/e &&\n+\n+\ttest_tick &&\n+\tgit commit -m \"master modifies a and d/e\" &&\n+\tc1=$(git rev-parse --verify HEAD) &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o1\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o1\td/e\"\n+\t\techo \"100644 $o1 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o1 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'setup 2' '\n+\n+\trm -rf [abcd] &&\n+\tgit checkout conflict &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o0\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o0\td/e\"\n+\t\techo \"100644 $o0 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o0 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual &&\n+\n+\techo goodbye >>a &&\n+\to2=$(git hash-object a) &&\n+\n+\tgit add a &&\n+\n+\ttest_tick &&\n+\tgit commit -m \"conflict modifies a\" &&\n+\tc2=$(git rev-parse --verify HEAD) &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o2\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o0\td/e\"\n+\t\techo \"100644 $o2 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o0 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'setup 3' '\n+\n+\trm -rf [abcd] &&\n+\tgit checkout noconflict &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o0\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o0\td/e\"\n+\t\techo \"100644 $o0 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o0 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual &&\n+\n+\techo hello >>a &&\n+\to3=$(git hash-object a) &&\n+\n+\tgit add a &&\n+\n+\ttest_tick &&\n+\tgit commit -m \"noconflict modifies a\" &&\n+\tc3=$(git rev-parse --verify HEAD) &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o3\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o0\td/e\"\n+\t\techo \"100644 $o3 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o0 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'setup 4' '\n+\n+\trm -rf [abcd] &&\n+\tgit checkout conflict-inside &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o0\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o0\td/e\"\n+\t\techo \"100644 $o0 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o0 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual &&\n+\n+\tmkdir d &&\n+\techo goodbye >>d/e &&\n+\to4=$(git hash-object d/e) &&\n+\n+\tgit add d/e &&\n+\n+\ttest_tick &&\n+\tgit commit -m \"conflict-inside modifies d/e\" &&\n+\tc4=$(git rev-parse --verify HEAD) &&\n+\t( git ls-tree -r HEAD ; git ls-files -s ) >actual &&\n+\t(\n+\t\techo \"100644 blob $o0\ta\"\n+\t\techo \"100644 blob $o0\tb\"\n+\t\techo \"100644 blob $o0\tc\"\n+\t\techo \"100644 blob $o4\td/e\"\n+\t\techo \"100644 $o0 0\ta\"\n+\t\techo \"100644 $o0 0\tb\"\n+\t\techo \"100644 $o0 0\tc\"\n+\t\techo \"100644 $o4 0\td/e\"\n+\t) >expected &&\n+\ttest_cmp expected actual\n+'\n+\n+export GIT_INDEX_PREFIX=d/\n+\n+test_expect_success 'merge-recursive conflict inside' '\n+\n+\trm -fr [abcd] &&\n+\tgit checkout -f \"$c4\" &&\n+\n+\tgit-merge-recursive \"$c0\" -- \"$c4\" \"$c1\"\n+\tstatus=$?\n+\tcase \"$status\" in\n+\t1)\n+\t\t: happy\n+\t\t;;\n+\t*)\n+\t\techo >&2 \"why status $status!!!\"\n+\t\tfalse\n+\t\t;;\n+\tesac\n+'\n+\n+test_expect_success 'merge-recursive no conflict outside' '\n+\n+\trm -fr [abcd] &&\n+\tgit checkout -f \"$c3\" &&\n+\n+\tgit-merge-recursive \"$c0\" -- \"$c3\" \"$c1\"\n+\tstatus=$?\n+\tcase \"$status\" in\n+\t0)\n+\t\t: happy\n+\t\t;;\n+\t*)\n+\t\techo >&2 \"why status $status!!!\"\n+\t\tfalse\n+\t\t;;\n+\tesac\n+'\n+\n+test_expect_success 'merge-recursive conflict outside' '\n+\n+\trm -fr [abcd] &&\n+\tgit checkout -f \"$c2\" &&\n+\n+\tgit-merge-recursive \"$c0\" -- \"$c2\" \"$c1\"\n+\tstatus=$?\n+\tcase \"$status\" in\n+\t1)\n+\t\t: happy\n+\t\t;;\n+\t*)\n+\t\techo >&2 \"why status $status!!!\"\n+\t\tfalse\n+\t\t;;\n+\tesac\n+'\n+\n+test_done\n-- \n1.5.5.GIT\n"}]}