Add tests for index prefix
PATCH 2/2 Add tests for index prefix
--- 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
t/t2300-index-prefix.sh new file +207 -0
@@ -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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +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 <[email protected]> +Date: Thu Apr 7 15:13:13 2005 -0700 + + work/two + +:100644 100644 5626abf... 814f4a4... M work/one + +commit e63957619e33be2985dacdbb077f4c2ca7210319 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:13:13 2005 -0700 + + work/one + +:000000 100644 0000000... 5626abf... A work/one + +commit e6742a1800d08c749ebbc01d1f4ca03b66ff44e1 +Author: A U Thor <[email protected]> +Date: Thu Apr 7 15:13:13 2005 -0700 + + two + +:100644 100644 5626abf... 814f4a4... M one + +commit 1c60dc5aa63dc2956ceb3ccc399d04245bc2cc1b +Author: A U Thor <[email protected]> +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
t/t2301-index-prefix-merge-recursive.sh new file +221 -0
221 lines not on this page · raw message
Signature · 1 line
1.5.5.GIT