From 5549029427f93219f22f99f4d1f832a6ab484a1c Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Sat, 20 Feb 2016 17:18:41 +0100 Subject: tests: rename work-tree tests to *work-tree* "Work tree" or "working tree" is the name of a checked out tree, "worktree" the name of the command which manages several working trees. The naming of tests mixes these two, currently: $ls t/*worktree* t/t1501-worktree.sh t/t1509-root-worktree.sh t/t2025-worktree-add.sh t/t2026-worktree-prune.sh t/t2027-worktree-list.sh t/t2104-update-index-skip-worktree.sh t/t3320-notes-merge-worktrees.sh t/t7011-skip-worktree-reading.sh t/t7012-skip-worktree-writing.sh t/t7409-submodule-detached-worktree.sh $grep -l "git worktree" t/*.sh t/t0002-gitfile.sh t/t1400-update-ref.sh t/t2025-worktree-add.sh t/t2026-worktree-prune.sh t/t2027-worktree-list.sh t/t3320-notes-merge-worktrees.sh t/t7410-submodule-checkout-to.sh Rename t1501, t1509 and t7409 to make it clear on first glance that they test work tree related behavior, rather than the worktree command. t2104, t7011 and t7012 are about the "skip-worktree" flag so that their name should remain unchanged. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- t/t1501-work-tree.sh | 426 ++++++++++++++++++++++++++++++++ t/t1501-worktree.sh | 426 -------------------------------- t/t1509-root-work-tree.sh | 258 +++++++++++++++++++ t/t1509-root-worktree.sh | 258 ------------------- t/t7409-submodule-detached-work-tree.sh | 84 +++++++ t/t7409-submodule-detached-worktree.sh | 84 ------- 6 files changed, 768 insertions(+), 768 deletions(-) create mode 100755 t/t1501-work-tree.sh delete mode 100755 t/t1501-worktree.sh create mode 100755 t/t1509-root-work-tree.sh delete mode 100755 t/t1509-root-worktree.sh create mode 100755 t/t7409-submodule-detached-work-tree.sh delete mode 100755 t/t7409-submodule-detached-worktree.sh diff --git a/t/t1501-work-tree.sh b/t/t1501-work-tree.sh new file mode 100755 index 0000000000..cc5b870e58 --- /dev/null +++ b/t/t1501-work-tree.sh @@ -0,0 +1,426 @@ +#!/bin/sh + +test_description='test separate work tree' +. ./test-lib.sh + +test_expect_success 'setup' ' + EMPTY_TREE=$(git write-tree) && + EMPTY_BLOB=$(git hash-object -t blob --stdin expected.bare && + echo $2 >expected.inside-git && + echo $3 >expected.inside-worktree && + if test $# -ge 4 + then + echo $4 >expected.prefix + fi && + + git rev-parse --is-bare-repository >actual.bare && + git rev-parse --is-inside-git-dir >actual.inside-git && + git rev-parse --is-inside-work-tree >actual.inside-worktree && + if test $# -ge 4 + then + git rev-parse --show-prefix >actual.prefix + fi && + + test_cmp expected.bare actual.bare && + test_cmp expected.inside-git actual.inside-git && + test_cmp expected.inside-worktree actual.inside-worktree && + if test $# -ge 4 + then + # rev-parse --show-prefix should output + # a single newline when at the top of the work tree, + # but we test for that separately. + test -z "$4" && ! test -s actual.prefix || + test_cmp expected.prefix actual.prefix + fi + } +' + +test_expect_success 'setup: core.worktree = relative path' ' + sane_unset GIT_WORK_TREE && + GIT_DIR=repo.git && + GIT_CONFIG="$(pwd)"/$GIT_DIR/config && + export GIT_DIR GIT_CONFIG && + git config core.worktree ../work +' + +test_expect_success 'outside' ' + test_rev_parse false false false +' + +test_expect_success 'inside work tree' ' + ( + cd work && + GIT_DIR=../repo.git && + GIT_CONFIG="$(pwd)"/$GIT_DIR/config && + test_rev_parse false false true "" + ) +' + +test_expect_success 'empty prefix is actually written out' ' + echo >expected && + ( + cd work && + GIT_DIR=../repo.git && + GIT_CONFIG="$(pwd)"/$GIT_DIR/config && + git rev-parse --show-prefix >../actual + ) && + test_cmp expected actual +' + +test_expect_success 'subdir of work tree' ' + ( + cd work/sub/dir && + GIT_DIR=../../../repo.git && + GIT_CONFIG="$(pwd)"/$GIT_DIR/config && + test_rev_parse false false true sub/dir/ + ) +' + +test_expect_success 'setup: core.worktree = absolute path' ' + sane_unset GIT_WORK_TREE && + GIT_DIR=$(pwd)/repo.git && + GIT_CONFIG=$GIT_DIR/config && + export GIT_DIR GIT_CONFIG && + git config core.worktree "$(pwd)/work" +' + +test_expect_success 'outside' ' + test_rev_parse false false false && + ( + cd work2 && + test_rev_parse false false false + ) +' + +test_expect_success 'inside work tree' ' + ( + cd work && + test_rev_parse false false true "" + ) +' + +test_expect_success 'subdir of work tree' ' + ( + cd work/sub/dir && + test_rev_parse false false true sub/dir/ + ) +' + +test_expect_success 'setup: GIT_WORK_TREE=relative (override core.worktree)' ' + GIT_DIR=$(pwd)/repo.git && + GIT_CONFIG=$GIT_DIR/config && + git config core.worktree non-existent && + GIT_WORK_TREE=work && + export GIT_DIR GIT_CONFIG GIT_WORK_TREE +' + +test_expect_success 'outside' ' + test_rev_parse false false false && + ( + cd work2 && + test_rev_parse false false false + ) +' + +test_expect_success 'inside work tree' ' + ( + cd work && + GIT_WORK_TREE=. && + test_rev_parse false false true "" + ) +' + +test_expect_success 'subdir of work tree' ' + ( + cd work/sub/dir && + GIT_WORK_TREE=../.. && + test_rev_parse false false true sub/dir/ + ) +' + +test_expect_success 'setup: GIT_WORK_TREE=absolute, below git dir' ' + mv work repo.git/work && + mv work2 repo.git/work2 && + GIT_DIR=$(pwd)/repo.git && + GIT_CONFIG=$GIT_DIR/config && + GIT_WORK_TREE=$(pwd)/repo.git/work && + export GIT_DIR GIT_CONFIG GIT_WORK_TREE +' + +test_expect_success 'outside' ' + echo outside && + test_rev_parse false false false +' + +test_expect_success 'in repo.git' ' + ( + cd repo.git && + test_rev_parse false true false + ) && + ( + cd repo.git/objects && + test_rev_parse false true false + ) && + ( + cd repo.git/work2 && + test_rev_parse false true false + ) +' + +test_expect_success 'inside work tree' ' + ( + cd repo.git/work && + test_rev_parse false true true "" + ) +' + +test_expect_success 'subdir of work tree' ' + ( + cd repo.git/work/sub/dir && + test_rev_parse false true true sub/dir/ + ) +' + +test_expect_success 'find work tree from repo' ' + echo sub/dir/untracked >expected && + cat <<-\EOF >repo.git/work/.gitignore && + expected.* + actual.* + .gitignore + EOF + >repo.git/work/sub/dir/untracked && + ( + cd repo.git && + git ls-files --others --exclude-standard >../actual + ) && + test_cmp expected actual +' + +test_expect_success 'find work tree from work tree' ' + echo sub/dir/tracked >expected && + >repo.git/work/sub/dir/tracked && + ( + cd repo.git/work/sub/dir && + git --git-dir=../../.. add tracked + ) && + ( + cd repo.git && + git ls-files >../actual + ) && + test_cmp expected actual +' + +test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' ' + ( + cd repo.git/work/sub/dir && + GIT_DIR=../../.. && + GIT_WORK_TREE=../.. && + GIT_PAGER= && + export GIT_DIR GIT_WORK_TREE GIT_PAGER && + + git diff --exit-code tracked && + echo changed >tracked && + test_must_fail git diff --exit-code tracked + ) +' + +test_expect_success 'diff-index respects work tree under .git dir' ' + cat >diff-index-cached.expected <<-EOF && + :000000 100644 $_z40 $EMPTY_BLOB A sub/dir/tracked + EOF + cat >diff-index.expected <<-EOF && + :000000 100644 $_z40 $_z40 A sub/dir/tracked + EOF + + ( + GIT_DIR=repo.git && + GIT_WORK_TREE=repo.git/work && + export GIT_DIR GIT_WORK_TREE && + git diff-index $EMPTY_TREE >diff-index.actual && + git diff-index --cached $EMPTY_TREE >diff-index-cached.actual + ) && + test_cmp diff-index.expected diff-index.actual && + test_cmp diff-index-cached.expected diff-index-cached.actual +' + +test_expect_success 'diff-files respects work tree under .git dir' ' + cat >diff-files.expected <<-EOF && + :100644 100644 $EMPTY_BLOB $_z40 M sub/dir/tracked + EOF + + ( + GIT_DIR=repo.git && + GIT_WORK_TREE=repo.git/work && + export GIT_DIR GIT_WORK_TREE && + git diff-files >diff-files.actual + ) && + test_cmp diff-files.expected diff-files.actual +' + +test_expect_success 'git diff respects work tree under .git dir' ' + cat >diff-TREE.expected <<-EOF && + diff --git a/sub/dir/tracked b/sub/dir/tracked + new file mode 100644 + index 0000000..$CHANGED_BLOB7 + --- /dev/null + +++ b/sub/dir/tracked + @@ -0,0 +1 @@ + +changed + EOF + cat >diff-TREE-cached.expected <<-EOF && + diff --git a/sub/dir/tracked b/sub/dir/tracked + new file mode 100644 + index 0000000..$EMPTY_BLOB7 + EOF + cat >diff-FILES.expected <<-EOF && + diff --git a/sub/dir/tracked b/sub/dir/tracked + index $EMPTY_BLOB7..$CHANGED_BLOB7 100644 + --- a/sub/dir/tracked + +++ b/sub/dir/tracked + @@ -0,0 +1 @@ + +changed + EOF + + ( + GIT_DIR=repo.git && + GIT_WORK_TREE=repo.git/work && + export GIT_DIR GIT_WORK_TREE && + git diff $EMPTY_TREE >diff-TREE.actual && + git diff --cached $EMPTY_TREE >diff-TREE-cached.actual && + git diff >diff-FILES.actual + ) && + test_cmp diff-TREE.expected diff-TREE.actual && + test_cmp diff-TREE-cached.expected diff-TREE-cached.actual && + test_cmp diff-FILES.expected diff-FILES.actual +' + +test_expect_success 'git grep' ' + echo dir/tracked >expected.grep && + ( + cd repo.git/work/sub && + GIT_DIR=../.. && + GIT_WORK_TREE=.. && + export GIT_DIR GIT_WORK_TREE && + git grep -l changed >../../../actual.grep + ) && + test_cmp expected.grep actual.grep +' + +test_expect_success 'git commit' ' + ( + cd repo.git && + GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done + ) +' + +test_expect_success 'absolute pathspec should fail gracefully' ' + ( + cd repo.git && + test_might_fail git config --unset core.worktree && + test_must_fail git log HEAD -- /home + ) +' + +test_expect_success 'make_relative_path handles double slashes in GIT_DIR' ' + >dummy_file && + echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file && + git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file +' + +test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' ' + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \ + test-subprocess --setup-work-tree rev-parse --show-toplevel >actual && + echo "$(pwd)/repo.git/work" >expected && + test_cmp expected actual +' + +test_expect_success 'Multi-worktree setup' ' + mkdir work && + mkdir -p repo.git/repos/foo && + cp repo.git/HEAD repo.git/index repo.git/repos/foo && + test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo && + sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE +' + +test_expect_success 'GIT_DIR set (1)' ' + echo "gitdir: repo.git/repos/foo" >gitfile && + echo ../.. >repo.git/repos/foo/commondir && + ( + cd work && + GIT_DIR=../gitfile git rev-parse --git-common-dir >actual && + test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && + test_cmp expect actual + ) +' + +test_expect_success 'GIT_DIR set (2)' ' + echo "gitdir: repo.git/repos/foo" >gitfile && + echo "$(pwd)/repo.git" >repo.git/repos/foo/commondir && + ( + cd work && + GIT_DIR=../gitfile git rev-parse --git-common-dir >actual && + test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && + test_cmp expect actual + ) +' + +test_expect_success 'Auto discovery' ' + echo "gitdir: repo.git/repos/foo" >.git && + echo ../.. >repo.git/repos/foo/commondir && + ( + cd work && + git rev-parse --git-common-dir >actual && + test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && + test_cmp expect actual && + echo haha >data1 && + git add data1 && + git ls-files --full-name :/ | grep data1 >actual && + echo work/data1 >expect && + test_cmp expect actual + ) +' + +test_expect_success '$GIT_DIR/common overrides core.worktree' ' + mkdir elsewhere && + git --git-dir=repo.git config core.worktree "$TRASH_DIRECTORY/elsewhere" && + echo "gitdir: repo.git/repos/foo" >.git && + echo ../.. >repo.git/repos/foo/commondir && + ( + cd work && + git rev-parse --git-common-dir >actual && + test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && + test_cmp expect actual && + echo haha >data2 && + git add data2 && + git ls-files --full-name :/ | grep data2 >actual && + echo work/data2 >expect && + test_cmp expect actual + ) +' + +test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' ' + echo "gitdir: repo.git/repos/foo" >.git && + echo ../.. >repo.git/repos/foo/commondir && + ( + cd work && + echo haha >data3 && + git --git-dir=../.git --work-tree=. add data3 && + git ls-files --full-name -- :/ | grep data3 >actual && + echo data3 >expect && + test_cmp expect actual + ) +' + +test_done diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh deleted file mode 100755 index cc5b870e58..0000000000 --- a/t/t1501-worktree.sh +++ /dev/null @@ -1,426 +0,0 @@ -#!/bin/sh - -test_description='test separate work tree' -. ./test-lib.sh - -test_expect_success 'setup' ' - EMPTY_TREE=$(git write-tree) && - EMPTY_BLOB=$(git hash-object -t blob --stdin expected.bare && - echo $2 >expected.inside-git && - echo $3 >expected.inside-worktree && - if test $# -ge 4 - then - echo $4 >expected.prefix - fi && - - git rev-parse --is-bare-repository >actual.bare && - git rev-parse --is-inside-git-dir >actual.inside-git && - git rev-parse --is-inside-work-tree >actual.inside-worktree && - if test $# -ge 4 - then - git rev-parse --show-prefix >actual.prefix - fi && - - test_cmp expected.bare actual.bare && - test_cmp expected.inside-git actual.inside-git && - test_cmp expected.inside-worktree actual.inside-worktree && - if test $# -ge 4 - then - # rev-parse --show-prefix should output - # a single newline when at the top of the work tree, - # but we test for that separately. - test -z "$4" && ! test -s actual.prefix || - test_cmp expected.prefix actual.prefix - fi - } -' - -test_expect_success 'setup: core.worktree = relative path' ' - sane_unset GIT_WORK_TREE && - GIT_DIR=repo.git && - GIT_CONFIG="$(pwd)"/$GIT_DIR/config && - export GIT_DIR GIT_CONFIG && - git config core.worktree ../work -' - -test_expect_success 'outside' ' - test_rev_parse false false false -' - -test_expect_success 'inside work tree' ' - ( - cd work && - GIT_DIR=../repo.git && - GIT_CONFIG="$(pwd)"/$GIT_DIR/config && - test_rev_parse false false true "" - ) -' - -test_expect_success 'empty prefix is actually written out' ' - echo >expected && - ( - cd work && - GIT_DIR=../repo.git && - GIT_CONFIG="$(pwd)"/$GIT_DIR/config && - git rev-parse --show-prefix >../actual - ) && - test_cmp expected actual -' - -test_expect_success 'subdir of work tree' ' - ( - cd work/sub/dir && - GIT_DIR=../../../repo.git && - GIT_CONFIG="$(pwd)"/$GIT_DIR/config && - test_rev_parse false false true sub/dir/ - ) -' - -test_expect_success 'setup: core.worktree = absolute path' ' - sane_unset GIT_WORK_TREE && - GIT_DIR=$(pwd)/repo.git && - GIT_CONFIG=$GIT_DIR/config && - export GIT_DIR GIT_CONFIG && - git config core.worktree "$(pwd)/work" -' - -test_expect_success 'outside' ' - test_rev_parse false false false && - ( - cd work2 && - test_rev_parse false false false - ) -' - -test_expect_success 'inside work tree' ' - ( - cd work && - test_rev_parse false false true "" - ) -' - -test_expect_success 'subdir of work tree' ' - ( - cd work/sub/dir && - test_rev_parse false false true sub/dir/ - ) -' - -test_expect_success 'setup: GIT_WORK_TREE=relative (override core.worktree)' ' - GIT_DIR=$(pwd)/repo.git && - GIT_CONFIG=$GIT_DIR/config && - git config core.worktree non-existent && - GIT_WORK_TREE=work && - export GIT_DIR GIT_CONFIG GIT_WORK_TREE -' - -test_expect_success 'outside' ' - test_rev_parse false false false && - ( - cd work2 && - test_rev_parse false false false - ) -' - -test_expect_success 'inside work tree' ' - ( - cd work && - GIT_WORK_TREE=. && - test_rev_parse false false true "" - ) -' - -test_expect_success 'subdir of work tree' ' - ( - cd work/sub/dir && - GIT_WORK_TREE=../.. && - test_rev_parse false false true sub/dir/ - ) -' - -test_expect_success 'setup: GIT_WORK_TREE=absolute, below git dir' ' - mv work repo.git/work && - mv work2 repo.git/work2 && - GIT_DIR=$(pwd)/repo.git && - GIT_CONFIG=$GIT_DIR/config && - GIT_WORK_TREE=$(pwd)/repo.git/work && - export GIT_DIR GIT_CONFIG GIT_WORK_TREE -' - -test_expect_success 'outside' ' - echo outside && - test_rev_parse false false false -' - -test_expect_success 'in repo.git' ' - ( - cd repo.git && - test_rev_parse false true false - ) && - ( - cd repo.git/objects && - test_rev_parse false true false - ) && - ( - cd repo.git/work2 && - test_rev_parse false true false - ) -' - -test_expect_success 'inside work tree' ' - ( - cd repo.git/work && - test_rev_parse false true true "" - ) -' - -test_expect_success 'subdir of work tree' ' - ( - cd repo.git/work/sub/dir && - test_rev_parse false true true sub/dir/ - ) -' - -test_expect_success 'find work tree from repo' ' - echo sub/dir/untracked >expected && - cat <<-\EOF >repo.git/work/.gitignore && - expected.* - actual.* - .gitignore - EOF - >repo.git/work/sub/dir/untracked && - ( - cd repo.git && - git ls-files --others --exclude-standard >../actual - ) && - test_cmp expected actual -' - -test_expect_success 'find work tree from work tree' ' - echo sub/dir/tracked >expected && - >repo.git/work/sub/dir/tracked && - ( - cd repo.git/work/sub/dir && - git --git-dir=../../.. add tracked - ) && - ( - cd repo.git && - git ls-files >../actual - ) && - test_cmp expected actual -' - -test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' ' - ( - cd repo.git/work/sub/dir && - GIT_DIR=../../.. && - GIT_WORK_TREE=../.. && - GIT_PAGER= && - export GIT_DIR GIT_WORK_TREE GIT_PAGER && - - git diff --exit-code tracked && - echo changed >tracked && - test_must_fail git diff --exit-code tracked - ) -' - -test_expect_success 'diff-index respects work tree under .git dir' ' - cat >diff-index-cached.expected <<-EOF && - :000000 100644 $_z40 $EMPTY_BLOB A sub/dir/tracked - EOF - cat >diff-index.expected <<-EOF && - :000000 100644 $_z40 $_z40 A sub/dir/tracked - EOF - - ( - GIT_DIR=repo.git && - GIT_WORK_TREE=repo.git/work && - export GIT_DIR GIT_WORK_TREE && - git diff-index $EMPTY_TREE >diff-index.actual && - git diff-index --cached $EMPTY_TREE >diff-index-cached.actual - ) && - test_cmp diff-index.expected diff-index.actual && - test_cmp diff-index-cached.expected diff-index-cached.actual -' - -test_expect_success 'diff-files respects work tree under .git dir' ' - cat >diff-files.expected <<-EOF && - :100644 100644 $EMPTY_BLOB $_z40 M sub/dir/tracked - EOF - - ( - GIT_DIR=repo.git && - GIT_WORK_TREE=repo.git/work && - export GIT_DIR GIT_WORK_TREE && - git diff-files >diff-files.actual - ) && - test_cmp diff-files.expected diff-files.actual -' - -test_expect_success 'git diff respects work tree under .git dir' ' - cat >diff-TREE.expected <<-EOF && - diff --git a/sub/dir/tracked b/sub/dir/tracked - new file mode 100644 - index 0000000..$CHANGED_BLOB7 - --- /dev/null - +++ b/sub/dir/tracked - @@ -0,0 +1 @@ - +changed - EOF - cat >diff-TREE-cached.expected <<-EOF && - diff --git a/sub/dir/tracked b/sub/dir/tracked - new file mode 100644 - index 0000000..$EMPTY_BLOB7 - EOF - cat >diff-FILES.expected <<-EOF && - diff --git a/sub/dir/tracked b/sub/dir/tracked - index $EMPTY_BLOB7..$CHANGED_BLOB7 100644 - --- a/sub/dir/tracked - +++ b/sub/dir/tracked - @@ -0,0 +1 @@ - +changed - EOF - - ( - GIT_DIR=repo.git && - GIT_WORK_TREE=repo.git/work && - export GIT_DIR GIT_WORK_TREE && - git diff $EMPTY_TREE >diff-TREE.actual && - git diff --cached $EMPTY_TREE >diff-TREE-cached.actual && - git diff >diff-FILES.actual - ) && - test_cmp diff-TREE.expected diff-TREE.actual && - test_cmp diff-TREE-cached.expected diff-TREE-cached.actual && - test_cmp diff-FILES.expected diff-FILES.actual -' - -test_expect_success 'git grep' ' - echo dir/tracked >expected.grep && - ( - cd repo.git/work/sub && - GIT_DIR=../.. && - GIT_WORK_TREE=.. && - export GIT_DIR GIT_WORK_TREE && - git grep -l changed >../../../actual.grep - ) && - test_cmp expected.grep actual.grep -' - -test_expect_success 'git commit' ' - ( - cd repo.git && - GIT_DIR=. GIT_WORK_TREE=work git commit -a -m done - ) -' - -test_expect_success 'absolute pathspec should fail gracefully' ' - ( - cd repo.git && - test_might_fail git config --unset core.worktree && - test_must_fail git log HEAD -- /home - ) -' - -test_expect_success 'make_relative_path handles double slashes in GIT_DIR' ' - >dummy_file && - echo git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file && - git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file -' - -test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' ' - GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \ - test-subprocess --setup-work-tree rev-parse --show-toplevel >actual && - echo "$(pwd)/repo.git/work" >expected && - test_cmp expected actual -' - -test_expect_success 'Multi-worktree setup' ' - mkdir work && - mkdir -p repo.git/repos/foo && - cp repo.git/HEAD repo.git/index repo.git/repos/foo && - test_might_fail cp repo.git/sharedindex.* repo.git/repos/foo && - sane_unset GIT_DIR GIT_CONFIG GIT_WORK_TREE -' - -test_expect_success 'GIT_DIR set (1)' ' - echo "gitdir: repo.git/repos/foo" >gitfile && - echo ../.. >repo.git/repos/foo/commondir && - ( - cd work && - GIT_DIR=../gitfile git rev-parse --git-common-dir >actual && - test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && - test_cmp expect actual - ) -' - -test_expect_success 'GIT_DIR set (2)' ' - echo "gitdir: repo.git/repos/foo" >gitfile && - echo "$(pwd)/repo.git" >repo.git/repos/foo/commondir && - ( - cd work && - GIT_DIR=../gitfile git rev-parse --git-common-dir >actual && - test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && - test_cmp expect actual - ) -' - -test_expect_success 'Auto discovery' ' - echo "gitdir: repo.git/repos/foo" >.git && - echo ../.. >repo.git/repos/foo/commondir && - ( - cd work && - git rev-parse --git-common-dir >actual && - test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && - test_cmp expect actual && - echo haha >data1 && - git add data1 && - git ls-files --full-name :/ | grep data1 >actual && - echo work/data1 >expect && - test_cmp expect actual - ) -' - -test_expect_success '$GIT_DIR/common overrides core.worktree' ' - mkdir elsewhere && - git --git-dir=repo.git config core.worktree "$TRASH_DIRECTORY/elsewhere" && - echo "gitdir: repo.git/repos/foo" >.git && - echo ../.. >repo.git/repos/foo/commondir && - ( - cd work && - git rev-parse --git-common-dir >actual && - test-path-utils real_path "$TRASH_DIRECTORY/repo.git" >expect && - test_cmp expect actual && - echo haha >data2 && - git add data2 && - git ls-files --full-name :/ | grep data2 >actual && - echo work/data2 >expect && - test_cmp expect actual - ) -' - -test_expect_success '$GIT_WORK_TREE overrides $GIT_DIR/common' ' - echo "gitdir: repo.git/repos/foo" >.git && - echo ../.. >repo.git/repos/foo/commondir && - ( - cd work && - echo haha >data3 && - git --git-dir=../.git --work-tree=. add data3 && - git ls-files --full-name -- :/ | grep data3 >actual && - echo data3 >expect && - test_cmp expect actual - ) -' - -test_done diff --git a/t/t1509-root-work-tree.sh b/t/t1509-root-work-tree.sh new file mode 100755 index 0000000000..553a3f601b --- /dev/null +++ b/t/t1509-root-work-tree.sh @@ -0,0 +1,258 @@ +#!/bin/sh + +test_description='Test Git when git repository is located at root + +This test requires write access in root. Do not bother if you do not +have a throwaway chroot or VM. + +Script t1509/prepare-chroot.sh may help you setup chroot, then you +can chroot in and execute this test from there. +' + +. ./test-lib.sh + +test_cmp_val() { + echo "$1" > expected + echo "$2" > result + test_cmp expected result +} + +test_vars() { + test_expect_success "$1: gitdir" ' + test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)" + ' + + test_expect_success "$1: worktree" ' + test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)" + ' + + test_expect_success "$1: prefix" ' + test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)" + ' +} + +test_foobar_root() { + test_expect_success 'add relative' ' + test -z "$(cd / && git ls-files)" && + git add foo/foome && + git add foo/bar/barme && + git add me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' + + test_expect_success 'add absolute' ' + test -z "$(cd / && git ls-files)" && + git add /foo/foome && + git add /foo/bar/barme && + git add /me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' + +} + +test_foobar_foo() { + test_expect_success 'add relative' ' + test -z "$(cd / && git ls-files)" && + git add foome && + git add bar/barme && + git add ../me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' + + test_expect_success 'add absolute' ' + test -z "$(cd / && git ls-files)" && + git add /foo/foome && + git add /foo/bar/barme && + git add /me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' +} + +test_foobar_foobar() { + test_expect_success 'add relative' ' + test -z "$(cd / && git ls-files)" && + git add ../foome && + git add barme && + git add ../../me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' + + test_expect_success 'add absolute' ' + test -z "$(cd / && git ls-files)" && + git add /foo/foome && + git add /foo/bar/barme && + git add /me && + ( cd / && git ls-files --stage ) > result && + test_cmp /ls.expected result && + rm "$(git rev-parse --git-dir)/index" + ' +} + +if ! test -w / +then + skip_all="Test requiring writable / skipped. Read this test if you want to run it" + test_done +fi + +if test -e /refs || test -e /objects || test -e /info || test -e /hooks || + test -e /.git || test -e /foo || test -e /me +then + skip_all="Skip test that clobbers existing files in /" + test_done +fi + +if [ "$IKNOWWHATIAMDOING" != "YES" ]; then + skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test" + test_done +fi + +if ! test_have_prereq NOT_ROOT +then + skip_all="No you can't run this as root" + test_done +fi + +ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d + +test_expect_success 'setup' ' + rm -rf /foo && + mkdir /foo && + mkdir /foo/bar && + echo 1 > /foo/foome && + echo 1 > /foo/bar/barme && + echo 1 > /me +' + +say "GIT_DIR absolute, GIT_WORK_TREE set" + +test_expect_success 'go to /' 'cd /' + +cat >ls.expected < expected && + git init > result && + test_cmp expected result +' + +test_vars 'auto gitdir, root' ".git" "/" "" +test_foobar_root + +test_expect_success 'go to /foo' 'cd /foo' +test_vars 'auto gitdir, foo' "/.git" "/" "foo/" +test_foobar_foo + +test_expect_success 'go to /foo/bar' 'cd /foo/bar' +test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/" +test_foobar_foobar + +test_expect_success 'cleanup' 'rm -rf /.git' + +say "auto bare gitdir" + +# DESTROYYYYY!!!!! +test_expect_success 'setup' ' + rm -rf /refs /objects /info /hooks && + rm -f /expected /ls.expected /me /result && + cd / && + echo "Initialized empty Git repository in /" > expected && + git init --bare > result && + test_cmp expected result +' + +test_vars 'auto gitdir, root' "." "" "" + +test_expect_success 'go to /foo' 'cd /foo' + +test_vars 'auto gitdir, root' "/" "" "" + +test_done diff --git a/t/t1509-root-worktree.sh b/t/t1509-root-worktree.sh deleted file mode 100755 index 553a3f601b..0000000000 --- a/t/t1509-root-worktree.sh +++ /dev/null @@ -1,258 +0,0 @@ -#!/bin/sh - -test_description='Test Git when git repository is located at root - -This test requires write access in root. Do not bother if you do not -have a throwaway chroot or VM. - -Script t1509/prepare-chroot.sh may help you setup chroot, then you -can chroot in and execute this test from there. -' - -. ./test-lib.sh - -test_cmp_val() { - echo "$1" > expected - echo "$2" > result - test_cmp expected result -} - -test_vars() { - test_expect_success "$1: gitdir" ' - test_cmp_val "'"$2"'" "$(git rev-parse --git-dir)" - ' - - test_expect_success "$1: worktree" ' - test_cmp_val "'"$3"'" "$(git rev-parse --show-toplevel)" - ' - - test_expect_success "$1: prefix" ' - test_cmp_val "'"$4"'" "$(git rev-parse --show-prefix)" - ' -} - -test_foobar_root() { - test_expect_success 'add relative' ' - test -z "$(cd / && git ls-files)" && - git add foo/foome && - git add foo/bar/barme && - git add me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' - - test_expect_success 'add absolute' ' - test -z "$(cd / && git ls-files)" && - git add /foo/foome && - git add /foo/bar/barme && - git add /me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' - -} - -test_foobar_foo() { - test_expect_success 'add relative' ' - test -z "$(cd / && git ls-files)" && - git add foome && - git add bar/barme && - git add ../me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' - - test_expect_success 'add absolute' ' - test -z "$(cd / && git ls-files)" && - git add /foo/foome && - git add /foo/bar/barme && - git add /me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' -} - -test_foobar_foobar() { - test_expect_success 'add relative' ' - test -z "$(cd / && git ls-files)" && - git add ../foome && - git add barme && - git add ../../me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' - - test_expect_success 'add absolute' ' - test -z "$(cd / && git ls-files)" && - git add /foo/foome && - git add /foo/bar/barme && - git add /me && - ( cd / && git ls-files --stage ) > result && - test_cmp /ls.expected result && - rm "$(git rev-parse --git-dir)/index" - ' -} - -if ! test -w / -then - skip_all="Test requiring writable / skipped. Read this test if you want to run it" - test_done -fi - -if test -e /refs || test -e /objects || test -e /info || test -e /hooks || - test -e /.git || test -e /foo || test -e /me -then - skip_all="Skip test that clobbers existing files in /" - test_done -fi - -if [ "$IKNOWWHATIAMDOING" != "YES" ]; then - skip_all="You must set env var IKNOWWHATIAMDOING=YES in order to run this test" - test_done -fi - -if ! test_have_prereq NOT_ROOT -then - skip_all="No you can't run this as root" - test_done -fi - -ONE_SHA1=d00491fd7e5bb6fa28c517a0bb32b8b506539d4d - -test_expect_success 'setup' ' - rm -rf /foo && - mkdir /foo && - mkdir /foo/bar && - echo 1 > /foo/foome && - echo 1 > /foo/bar/barme && - echo 1 > /me -' - -say "GIT_DIR absolute, GIT_WORK_TREE set" - -test_expect_success 'go to /' 'cd /' - -cat >ls.expected < expected && - git init > result && - test_cmp expected result -' - -test_vars 'auto gitdir, root' ".git" "/" "" -test_foobar_root - -test_expect_success 'go to /foo' 'cd /foo' -test_vars 'auto gitdir, foo' "/.git" "/" "foo/" -test_foobar_foo - -test_expect_success 'go to /foo/bar' 'cd /foo/bar' -test_vars 'auto gitdir, foo/bar' "/.git" "/" "foo/bar/" -test_foobar_foobar - -test_expect_success 'cleanup' 'rm -rf /.git' - -say "auto bare gitdir" - -# DESTROYYYYY!!!!! -test_expect_success 'setup' ' - rm -rf /refs /objects /info /hooks && - rm -f /expected /ls.expected /me /result && - cd / && - echo "Initialized empty Git repository in /" > expected && - git init --bare > result && - test_cmp expected result -' - -test_vars 'auto gitdir, root' "." "" "" - -test_expect_success 'go to /foo' 'cd /foo' - -test_vars 'auto gitdir, root' "/" "" "" - -test_done diff --git a/t/t7409-submodule-detached-work-tree.sh b/t/t7409-submodule-detached-work-tree.sh new file mode 100755 index 0000000000..c20717181e --- /dev/null +++ b/t/t7409-submodule-detached-work-tree.sh @@ -0,0 +1,84 @@ +#!/bin/sh +# +# Copyright (c) 2012 Daniel Graña +# + +test_description='Test submodules on detached working tree + +This test verifies that "git submodule" initialization, update and addition works +on detahced working trees +' + +TEST_NO_CREATE_REPO=1 +. ./test-lib.sh + +test_expect_success 'submodule on detached working tree' ' + git init --bare remote && + test_create_repo bundle1 && + ( + cd bundle1 && + test_commit "shoot" && + git rev-parse --verify HEAD >../expect + ) && + mkdir home && + ( + cd home && + GIT_WORK_TREE="$(pwd)" && + GIT_DIR="$(pwd)/.dotfiles" && + export GIT_WORK_TREE GIT_DIR && + git clone --bare ../remote .dotfiles && + git submodule add ../bundle1 .vim/bundle/sogood && + test_commit "sogood" && + ( + unset GIT_WORK_TREE GIT_DIR && + cd .vim/bundle/sogood && + git rev-parse --verify HEAD >actual && + test_cmp ../../../../expect actual + ) && + git push origin master + ) && + mkdir home2 && + ( + cd home2 && + git clone --bare ../remote .dotfiles && + GIT_WORK_TREE="$(pwd)" && + GIT_DIR="$(pwd)/.dotfiles" && + export GIT_WORK_TREE GIT_DIR && + git checkout master && + git submodule update --init && + ( + unset GIT_WORK_TREE GIT_DIR && + cd .vim/bundle/sogood && + git rev-parse --verify HEAD >actual && + test_cmp ../../../../expect actual + ) + ) +' + +test_expect_success 'submodule on detached working pointed by core.worktree' ' + mkdir home3 && + ( + cd home3 && + GIT_DIR="$(pwd)/.dotfiles" && + export GIT_DIR && + git clone --bare ../remote "$GIT_DIR" && + git config core.bare false && + git config core.worktree .. && + git checkout master && + git submodule add ../bundle1 .vim/bundle/dupe && + test_commit "dupe" && + git push origin master + ) && + ( + cd home && + GIT_DIR="$(pwd)/.dotfiles" && + export GIT_DIR && + git config core.bare false && + git config core.worktree .. && + git pull && + git submodule update --init && + test -f .vim/bundle/dupe/shoot.t + ) +' + +test_done diff --git a/t/t7409-submodule-detached-worktree.sh b/t/t7409-submodule-detached-worktree.sh deleted file mode 100755 index c20717181e..0000000000 --- a/t/t7409-submodule-detached-worktree.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2012 Daniel Graña -# - -test_description='Test submodules on detached working tree - -This test verifies that "git submodule" initialization, update and addition works -on detahced working trees -' - -TEST_NO_CREATE_REPO=1 -. ./test-lib.sh - -test_expect_success 'submodule on detached working tree' ' - git init --bare remote && - test_create_repo bundle1 && - ( - cd bundle1 && - test_commit "shoot" && - git rev-parse --verify HEAD >../expect - ) && - mkdir home && - ( - cd home && - GIT_WORK_TREE="$(pwd)" && - GIT_DIR="$(pwd)/.dotfiles" && - export GIT_WORK_TREE GIT_DIR && - git clone --bare ../remote .dotfiles && - git submodule add ../bundle1 .vim/bundle/sogood && - test_commit "sogood" && - ( - unset GIT_WORK_TREE GIT_DIR && - cd .vim/bundle/sogood && - git rev-parse --verify HEAD >actual && - test_cmp ../../../../expect actual - ) && - git push origin master - ) && - mkdir home2 && - ( - cd home2 && - git clone --bare ../remote .dotfiles && - GIT_WORK_TREE="$(pwd)" && - GIT_DIR="$(pwd)/.dotfiles" && - export GIT_WORK_TREE GIT_DIR && - git checkout master && - git submodule update --init && - ( - unset GIT_WORK_TREE GIT_DIR && - cd .vim/bundle/sogood && - git rev-parse --verify HEAD >actual && - test_cmp ../../../../expect actual - ) - ) -' - -test_expect_success 'submodule on detached working pointed by core.worktree' ' - mkdir home3 && - ( - cd home3 && - GIT_DIR="$(pwd)/.dotfiles" && - export GIT_DIR && - git clone --bare ../remote "$GIT_DIR" && - git config core.bare false && - git config core.worktree .. && - git checkout master && - git submodule add ../bundle1 .vim/bundle/dupe && - test_commit "dupe" && - git push origin master - ) && - ( - cd home && - GIT_DIR="$(pwd)/.dotfiles" && - export GIT_DIR && - git config core.bare false && - git config core.worktree .. && - git pull && - git submodule update --init && - test -f .vim/bundle/dupe/shoot.t - ) -' - -test_done -- cgit v1.2.3