Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- t/t2302-sparse-worktree.sh | 113 ++++++++++++++ t/t2302/add-u.expected | 1 + t/t2302/add.expected | 2 + t/t2302/commit.expected | 14 ++ t/t2302/diff-1.expected | 7 + t/t2302/diff-cc.expected | 9 + t/t2302/grep-work.expected | 2 + t/t2302/grep.expected | 2 + t/t2302/ls-files.expected | 2 + t/t2303-sparse-worktree-apply.sh | 62 ++++++++ t/t2303/apply-initial.patch | 14 ++ t/t2303/apply-inside.patch | 7 + t/t2303/apply-leading-dirs.patch | 3 + t/t2303/apply-outside.patch | 7 + t/t2303/apply-remove.patch | 7 + t/t2303/apply-rename.expected | 13 ++ t/t2303/apply-rename.patch | 4 + t/t2304-sparse-worktree-merge-recursive.sh | 233 ++++++++++++++++++++++++++++ 18 files changed, 502 insertions(+), 0 deletions(-) create mode 100755 t/t2302-sparse-worktree.sh create mode 100644 t/t2302/add-u.expected create mode 100644 t/t2302/add.expected create mode 100644 t/t2302/commit.expected create mode 100644 t/t2302/diff-1.expected create mode 100644 t/t2302/diff-cc.expected create mode 100644 t/t2302/grep-work.expected create mode 100644 t/t2302/grep.expected create mode 100644 t/t2302/ls-files.expected create mode 100755 t/t2303-sparse-worktree-apply.sh create mode 100644 t/t2303/apply-initial.patch create mode 100644 t/t2303/apply-inside.patch create mode 100644 t/t2303/apply-leading-dirs.patch create mode 100644 t/t2303/apply-outside.patch create mode 100644 t/t2303/apply-remove.patch create mode 100644 t/t2303/apply-rename.expected create mode 100644 t/t2303/apply-rename.patch create mode 100755 t/t2304-sparse-worktree-merge-recursive.sh diff --git a/t/t2302-sparse-worktree.sh b/t/t2302-sparse-worktree.sh new file mode 100755 index 0000000..0aaee3e --- /dev/null +++ b/t/t2302-sparse-worktree.sh @@ -0,0 +1,113 @@ +#!/bin/sh + +test_description='sparse checkout -- worktree update + +This test makes sure all commands that will not write +worktree outside sparse prefix, once set. +' +. ./test-lib.sh + +test_expect_success 'setup' ' + test_tick && + mkdir work && + echo one > tracked && + cp tracked work/tracked && + cp tracked untracked && + cp tracked work/untracked && + cp tracked modified && + cp tracked work/modified && + git add tracked modified work/tracked work/modified && + echo two >> modified && + echo two >> work/modified && + git commit -m initial && + git config core.sparsecheckout work' + +test_expect_success 'rev-parse --show-sparse-prefix' ' + test "$(git rev-parse --show-sparse-prefix)" = "work" +' + +test_expect_success 'ls-files' ' + git ls-files | cmp ../t2302/ls-files.expected && + test "$(git ls-files -o)" = work/untracked && + test "$(git ls-files -o .)" = work/untracked && + test "$(git ls-files -m)" = work/modified + +' + +test_expect_success 'grep' 'git grep -l --no-external-grep one | cmp ../t2302/grep.expected' + +test_expect_success 'grep' ' + ( + cd work && + git grep -l --no-external-grep one | cmp ../../t2302/grep-work.expected + ) +' + +test_expect_success 'checkout-index' '! git checkout-index tracked' + +test_expect_success 'checkout-index -a' ' + mv work/modified work/modified.old && + git checkout-index -a && + mv work/modified.old work/modified +' + +test_expect_success 'checkout tracked' '! git checkout tracked' + +test_expect_success 'checkout work/tracked' 'rm work/tracked && git checkout work/tracked' + +test_expect_success 'clean' 'test "$(git clean -n)" = "Would remove work/untracked"' + +test_expect_success 'rm' '! git rm tracked && test -f tracked' + +test_expect_success 'add' ' + git add -n . | cmp ../t2302/add.expected && + git add -n -u | cmp ../t2302/add-u.expected && + ! git add -n modified +' + +test_expect_success 'commit' ' + test_tick && + echo one > work/one && + git add work/one + echo two >> work/one && + git commit -m one work/one && + git show HEAD > commit.result && + cmp commit.result ../t2302/commit.expected && + rm commit.result +' + +null_sha1=0000000000000000000000000000000000000000 +one_sha1=$(echo one|git hash-object --stdin) +onethree_sha1=$(echo -e "one\nthree"|git hash-object -w --stdin) +onefour_sha1=$(echo -e "one\nfour"|git hash-object -w --stdin) + +diff_expected=":100644 100644 $one_sha1 $null_sha1 M work/modified" +external_diff_pattern="^work/modified [^ ]* $one_sha1 100644 work/modified $null_sha1 100644\$" + +cat >index.info <<EOF +0 $null_sha1 work/modified +100644 $onethree_sha1 2 work/modified +100644 $onefour_sha1 3 work/modified +EOF + +test_expect_success 'diff-files' ' + test "$(git diff-files)" = "$diff_expected" && + test "$(git diff-files -- work/modified)" = "$diff_expected" + cp .git/index .git/index.save && + git update-index --index-info < index.info && + git diff-files --cc | diff - ../t2302/diff-cc.expected && + mv .git/index.save .git/index +' + +test_expect_success 'diff-index' ' + test "$(git diff-index HEAD)" = "$diff_expected" +' + +test_expect_success 'diff' ' + git diff HEAD | cmp ../t2302/diff-1.expected && + git diff | cmp ../t2302/diff-1.expected && + GIT_EXTERNAL_DIFF=echo git diff --ext-diff HEAD | grep -q "$external_diff_pattern" && + GIT_EXTERNAL_DIFF=echo git diff --ext-diff | grep -q "$external_diff_pattern" +' + +test_done diff --git a/t/t2302/add-u.expected b/t/t2302/add-u.expected new file mode 100644 index 0000000..e0d6f54 --- /dev/null +++ b/t/t2302/add-u.expected @@ -0,0 +1 @@ +add 'work/modified' diff --git a/t/t2302/add.expected b/t/t2302/add.expected new file mode 100644 index 0000000..4ee7b0d --- /dev/null +++ b/t/t2302/add.expected @@ -0,0 +1,2 @@ +add 'work/modified' +add 'work/untracked' diff --git a/t/t2302/commit.expected b/t/t2302/commit.expected new file mode 100644 index 0000000..7e629aa --- /dev/null +++ b/t/t2302/commit.expected @@ -0,0 +1,14 @@ +commit 33ce2cea204feebac3994cd4520cca60657e65de +Author: A U Thor <author@xxxxxxxxxxx> +Date: Thu Apr 7 15:14:13 2005 -0700 + + one + +diff --git a/work/one b/work/one +new file mode 100644 +index 0000000..814f4a4 +--- /dev/null ++++ b/work/one +@@ -0,0 +1,2 @@ ++one ++two diff --git a/t/t2302/diff-1.expected b/t/t2302/diff-1.expected new file mode 100644 index 0000000..67be4fb --- /dev/null +++ b/t/t2302/diff-1.expected @@ -0,0 +1,7 @@ +diff --git a/work/modified b/work/modified +index 5626abf..814f4a4 100644 +--- a/work/modified ++++ b/work/modified +@@ -1 +1,2 @@ + one ++two diff --git a/t/t2302/diff-cc.expected b/t/t2302/diff-cc.expected new file mode 100644 index 0000000..8ca66dd --- /dev/null +++ b/t/t2302/diff-cc.expected @@ -0,0 +1,9 @@ +diff --cc work/modified +index 4c7442b,a9c7698..0000000 +--- a/work/modified ++++ b/work/modified +@@@ -1,2 -1,2 +1,2 @@@ + one +- three + -four +++two diff --git a/t/t2302/grep-work.expected b/t/t2302/grep-work.expected new file mode 100644 index 0000000..c081ddd --- /dev/null +++ b/t/t2302/grep-work.expected @@ -0,0 +1,2 @@ +modified +tracked diff --git a/t/t2302/grep.expected b/t/t2302/grep.expected new file mode 100644 index 0000000..4ddbe70 --- /dev/null +++ b/t/t2302/grep.expected @@ -0,0 +1,2 @@ +work/modified +work/tracked diff --git a/t/t2302/ls-files.expected b/t/t2302/ls-files.expected new file mode 100644 index 0000000..4ddbe70 --- /dev/null +++ b/t/t2302/ls-files.expected @@ -0,0 +1,2 @@ +work/modified +work/tracked diff --git a/t/t2303-sparse-worktree-apply.sh b/t/t2303-sparse-worktree-apply.sh new file mode 100755 index 0000000..4aeaf53 --- /dev/null +++ b/t/t2303-sparse-worktree-apply.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +test_description='git-apply in subtree checkout' + +. ./test-lib.sh + +mkdir work + +test_apply() { + test_expect_success "$1" ' + git checkout . && + git config core.sparsecheckout work && + git apply ../t2303/apply-'$2'.patch && + git config --unset core.sparsecheckout && + git diff > apply.result && + cmp apply.result ../t2303/apply-'$2'.patch + ' +} + +test_expect_success 'apply on empty tree' ' + git config core.sparsecheckout work && + ! git apply ../t2303/apply-initial.patch && + git config --unset core.sparsecheckout +' + +test_expect_success 'apply successfully without sparse checkout' ' + git apply ../t2303/apply-initial.patch && + git apply --cached ../t2303/apply-initial.patch +' + +test_expect_success 'apply on modified tree outside' ' + git checkout . && + git config core.sparsecheckout work && + ! git apply ../t2303/apply-outside.patch && + git config --unset core.sparsecheckout +' + +test_apply 'apply on modified tree' inside + +test_apply 'apply removing file' remove + +test_expect_success 'apply creating leading directories' ' + git config core.sparsecheckout work && + git apply ../t2303/apply-leading-dirs.patch && + git config --unset core.sparsecheckout && + test -f work/for/me/now +' + +test_expect_success 'apply renaming file' ' + git checkout . && + touch a && + empty_sha1=$(git hash-object -w a) && + rm a && + git update-index --add --cacheinfo 100644 $empty_sha1 work/two && + git config core.sparsecheckout work && + git apply ../t2303/apply-rename.patch && + git config --unset core.sparsecheckout && + git diff > apply.result && + cmp apply.result ../t2303/apply-rename.expected +' + +test_done diff --git a/t/t2303/apply-initial.patch b/t/t2303/apply-initial.patch new file mode 100644 index 0000000..72bfd82 --- /dev/null +++ b/t/t2303/apply-initial.patch @@ -0,0 +1,14 @@ +diff --git a/one b/one +new file mode 100644 +index 0000000..5626abf +--- /dev/null ++++ b/one +@@ -0,0 +1 @@ ++one +diff --git a/work/one b/work/one +new file mode 100644 +index 0000000..da327ae +--- /dev/null ++++ b/work/one +@@ -0,0 +1 @@ ++work/one diff --git a/t/t2303/apply-inside.patch b/t/t2303/apply-inside.patch new file mode 100644 index 0000000..4f5c310 --- /dev/null +++ b/t/t2303/apply-inside.patch @@ -0,0 +1,7 @@ +diff --git a/work/one b/work/one +index da327ae..6317017 100644 +--- a/work/one ++++ b/work/one +@@ -1 +1,2 @@ + work/one ++more diff --git a/t/t2303/apply-leading-dirs.patch b/t/t2303/apply-leading-dirs.patch new file mode 100644 index 0000000..b55809f --- /dev/null +++ b/t/t2303/apply-leading-dirs.patch @@ -0,0 +1,3 @@ +diff --git a/work/for/me/now b/work/for/me/now +new file mode 100644 +index 0000000..e69de29 diff --git a/t/t2303/apply-outside.patch b/t/t2303/apply-outside.patch new file mode 100644 index 0000000..8a8d625 --- /dev/null +++ b/t/t2303/apply-outside.patch @@ -0,0 +1,7 @@ +diff --git a/one b/one +index 5626abf..9a72323 100644 +--- a/one ++++ b/one +@@ -1 +1,2 @@ + one ++more diff --git a/t/t2303/apply-remove.patch b/t/t2303/apply-remove.patch new file mode 100644 index 0000000..781c743 --- /dev/null +++ b/t/t2303/apply-remove.patch @@ -0,0 +1,7 @@ +diff --git a/work/one b/work/one +deleted file mode 100644 +index da327ae..0000000 +--- a/work/one ++++ /dev/null +@@ -1 +0,0 @@ +-work/one diff --git a/t/t2303/apply-rename.expected b/t/t2303/apply-rename.expected new file mode 100644 index 0000000..d19f719 --- /dev/null +++ b/t/t2303/apply-rename.expected @@ -0,0 +1,13 @@ +diff --git a/work/one b/work/one +deleted file mode 100644 +index da327ae..0000000 +--- a/work/one ++++ /dev/null +@@ -1 +0,0 @@ +-work/one +diff --git a/work/two b/work/two +index e69de29..da327ae 100644 +--- a/work/two ++++ b/work/two +@@ -0,0 +1 @@ ++work/one diff --git a/t/t2303/apply-rename.patch b/t/t2303/apply-rename.patch new file mode 100644 index 0000000..6f21947 --- /dev/null +++ b/t/t2303/apply-rename.patch @@ -0,0 +1,4 @@ +diff --git a/work/one b/work/two +similarity index 100% +rename from work/one +rename to work/two diff --git a/t/t2304-sparse-worktree-merge-recursive.sh b/t/t2304-sparse-worktree-merge-recursive.sh new file mode 100755 index 0000000..b1708d4 --- /dev/null +++ b/t/t2304-sparse-worktree-merge-recursive.sh @@ -0,0 +1,233 @@ +#!/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 +' + +echo "gitdir: $(pwd)/.git" > gitfile + +test_expect_success 'merge-recursive conflict inside' ' + + rm -fr [abcd] && + git checkout -f "$c4" && + + cp gitfile d/.git && cd d/ + git config core.sparsecheckout d + git-merge-recursive "$c0" -- "$c4" "$c1" + status=$? + git config --unset core.sparsecheckout + rm .git && cd .. + 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" && + + cp gitfile d/.git && cd d + git config core.sparsecheckout d + git-merge-recursive "$c0" -- "$c3" "$c1" + status=$? + git config --unset core.sparsecheckout + rm .git && cd .. + 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" && + + cp gitfile d/.git && cd d + git config core.sparsecheckout d + git-merge-recursive "$c0" -- "$c2" "$c1" + status=$? + git config --unset core.sparsecheckout + rm .git && cd .. + 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