Skip to contentSkip to conversation

tests for sparse checkout, index protection

PATCH In review Nguyễn Thái Ngọc Duy 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 5/12 tests for sparse checkout, index protection

---
 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
t/t2300-sparse-index.sh new file +156 -0
new file mode 100755
index 0000000..8b9d61f
@@ -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
t/t2300/diff-index-sub.expected new file +3 -0
new file mode 100644
index 0000000..49b1a47
@@ -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
t/t2300/log.expected new file +64 -0

64 lines not on this page · raw message

t/t2301-sparse-index-merge-recursive.sh new file +226 -0

226 lines not on this page · raw message

Signature · 1 line
1.5.5.GIT