{"thread":{"id":"9234","subject":"[PATCH 4/5] Add test for sanitized work-tree behaviour","startedAt":"2007-07-26T06:32:27Z","lastAt":"2007-07-26T14:05:23Z","messageCount":3,"participants":["Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"48653","messageId":"Pine.LNX.4.64.0707260732130.14781@racer.site","threadId":"9234","inReplyTo":null,"subject":"[PATCH 4/5] Add test for sanitized work-tree behaviour","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-26T06:32:27Z","receivedAt":"2007-07-26T06:32:27Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tThis test was also something that I almost got eye cancer from.\n\n\tI am very willing to extend this script with many more test\n\tcases.  Just give me a recipe what you would like to have tested.\n\n t/t1501-worktree.sh |  157 ++++++++++++++++++++++++++++----------------------\n 1 files changed, 88 insertions(+), 69 deletions(-)\n\ndiff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh\nindex aadeeab..145c28e 100755\n--- a/t/t1501-worktree.sh\n+++ b/t/t1501-worktree.sh\n@@ -3,90 +3,109 @@\n test_description='test separate work tree'\n . ./test-lib.sh\n \n+i=1\n+\n test_rev_parse() {\n-\tname=$1\n-\tshift\n-\n-\ttest_expect_success \"$name: is-bare-repository\" \\\n-\t\"test '$1' = \\\"\\$(git rev-parse --is-bare-repository)\\\"\"\n-\tshift\n-\t[ $# -eq 0 ] && return\n-\n-\ttest_expect_success \"$name: is-inside-git-dir\" \\\n-\t\"test '$1' = \\\"\\$(git rev-parse --is-inside-git-dir)\\\"\"\n-\tshift\n-\t[ $# -eq 0 ] && return\n-\n-\ttest_expect_success \"$name: is-inside-work-tree\" \\\n-\t\"test '$1' = \\\"\\$(git rev-parse --is-inside-work-tree)\\\"\"\n-\tshift\n-\t[ $# -eq 0 ] && return\n-\n-\ttest_expect_success \"$name: prefix\" \\\n-\t\"test '$1' = \\\"\\$(git rev-parse --show-prefix)\\\"\"\n-\tshift\n-\t[ $# -eq 0 ] && return\n+\tname=\"$1\"\n+\tfor option in --is-bare-repository --is-inside-git-dir \\\n+\t\t--is-inside-work-tree --show-prefix\n+\tdo\n+\t\tshift\n+\t\ttest_expect_success \"$name: $option\" \\\n+\t\t\t\"test '$1' = \\\"\\$(git rev-parse $option)\\\"\"\n+i=$(($i+1))\n+test $i = $STOPI && gdb --args git rev-parse $option\n+\t\ttest $# -eq 1 && return\n+\tdone\n+}\n+\n+# usage: set_repo <working directory> [<git dir> [<work tree> [env]]]\n+set_repo () {\n+\tcd \"$1\"\n+\tsay \"switching to $(pwd) with GIT_DIR $2\"\n+\n+\ttest -z \"$2\" || {\n+\t\tGIT_DIR=\"$2\"\n+\t\tGIT_CONFIG=\"$2\"/config\n+\t\texport GIT_DIR GIT_CONFIG\n+\t}\n+\n+\ttest -z \"$3\" ||\n+\tcase \"$4\" in\n+\tenv)\n+\t\tGIT_WORK_TREE=\"$3\"\n+\t\texport GIT_WORK_TREE\n+\t\tgit config core.workTree non-existent\n+\t;;\n+\t*)\n+\t\tgit config core.workTree \"$3\"\n+\tesac\n }\n \n-mkdir -p work/sub/dir || exit 1\n-mv .git repo.git || exit 1\n+test_expect_success 'setup' '\n+\tmkdir -p work/sub/dir &&\n+\tmv .git repo.git\n+'\n \n say \"core.worktree = relative path\"\n-export GIT_DIR=repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n-unset GIT_WORK_TREE\n-git config core.worktree ../work\n-test_rev_parse 'outside'      false false false\n-cd work || exit 1\n-export GIT_DIR=../repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n-test_rev_parse 'inside'       false false true ''\n-cd sub/dir || exit 1\n-export GIT_DIR=../../../repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n+\n+set_repo . repo.git ../work\n+test_rev_parse 'outside git dir' false false false\n+\n+set_repo work ../repo.git\n+test_rev_parse 'inside git dir' false false true ''\n+\n+set_repo sub/dir ../../../repo.git\n test_rev_parse 'subdirectory' false false true sub/dir/\n-cd ../../.. || exit 1\n+cd ../../..\n \n say \"core.worktree = absolute path\"\n-export GIT_DIR=$(pwd)/repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n-git config core.worktree \"$(pwd)/work\"\n-test_rev_parse 'outside'      false false false\n-cd work || exit 1\n-test_rev_parse 'inside'       false false true ''\n-cd sub/dir || exit 1\n+set_repo . $(pwd)/repo.git $(pwd)/work\n+test_rev_parse 'outside git dir' false false false\n+\n+set_repo work\n+test_rev_parse 'inside git dir' false false true ''\n+\n+set_repo sub/dir\n test_rev_parse 'subdirectory' false false true sub/dir/\n-cd ../../.. || exit 1\n+cd ../../..\n \n say \"GIT_WORK_TREE=relative path (override core.worktree)\"\n-export GIT_DIR=$(pwd)/repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n-git config core.worktree non-existent\n-export GIT_WORK_TREE=work\n-test_rev_parse 'outside'      false false false\n-cd work || exit 1\n-export GIT_WORK_TREE=.\n-test_rev_parse 'inside'       false false true ''\n-cd sub/dir || exit 1\n-export GIT_WORK_TREE=../..\n+\n+set_repo . $(pwd)/repo.git work env\n+test_rev_parse 'outside git dir' false false false\n+\n+set_repo work \"\" . env\n+test_rev_parse 'inside git dir' false false true ''\n+\n+set_repo sub/dir \"\" ../../ env\n test_rev_parse 'subdirectory' false false true sub/dir/\n cd ../../.. || exit 1\n \n+say \"GIT_WORK_TREE=absolute path, work tree below git dir\"\n+\n mv work repo.git/work\n \n-say \"GIT_WORK_TREE=absolute path, work tree below git dir\"\n-export GIT_DIR=$(pwd)/repo.git\n-export GIT_CONFIG=$GIT_DIR/config\n-export GIT_WORK_TREE=$(pwd)/repo.git/work\n-test_rev_parse 'outside'              false false false\n-cd repo.git || exit 1\n-test_rev_parse 'in repo.git'              false true  false\n-cd objects || exit 1\n-test_rev_parse 'in repo.git/objects'      false true  false\n-cd ../work || exit 1\n-test_rev_parse 'in repo.git/work'         false false true ''\n-cd sub/dir || exit 1\n-test_rev_parse 'in repo.git/sub/dir' false false true sub/dir/\n-cd ../../../.. || exit 1\n+set_repo . $(pwd)/repo.git $(pwd)/repo.git/work env\n+test_rev_parse 'outside git dir' false false false\n+\n+set_repo repo.git\n+test_rev_parse 'in repo.git' false true false\n+\n+set_repo objects\n+test_rev_parse 'in repo.git/objects' false true  false\n+\n+set_repo ../work\n+test_rev_parse 'in repo.git/work' false true true ''\n+\n+set_repo sub/dir\n+test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/\n+cd ../../../..\n+\n+test_expect_success 'repo finds its work tree' '\n+\t(cd repo.git &&\n+\t : > work/sub/dir/untracked &&\n+\t test sub/dir/untracked = \"$(git ls-files --others)\")\n+'\n \n test_done\n-- \n1.5.3.rc2.42.gda8d-dirty\n"},{"id":"48670","messageId":"7vfy3b8wkp.fsf@assigned-by-dhcp.cox.net","threadId":"9234","inReplyTo":"Pine.LNX.4.64.0707260732130.14781@racer.site","subject":"Re: [PATCH 4/5] Add test for sanitized work-tree behaviour","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-26T07:15:34Z","receivedAt":"2007-07-26T07:15:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n> ...\n> @@ -3,90 +3,109 @@\n>  test_description='test separate work tree'\n>  . ./test-lib.sh\n>  \n> +i=1\n> +\n>  test_rev_parse() {\n> - ...\n> +\tname=\"$1\"\n> +\tfor option in --is-bare-repository --is-inside-git-dir \\\n> +\t\t--is-inside-work-tree --show-prefix\n> +\tdo\n> +\t\tshift\n> +\t\ttest_expect_success \"$name: $option\" \\\n> +\t\t\t\"test '$1' = \\\"\\$(git rev-parse $option)\\\"\"\n\n> +i=$(($i+1))\n> +test $i = $STOPI && gdb --args git rev-parse $option\n\nEh?\n"},{"id":"48705","messageId":"Pine.LNX.4.64.0707261503530.14781@racer.site","threadId":"9234","inReplyTo":"7vfy3b8wkp.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 4/5] Add test for sanitized work-tree behaviour","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-07-26T14:05:23Z","receivedAt":"2007-07-26T14:05:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 26 Jul 2007, Junio C Hamano wrote:\n\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n> \n> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> > ---\n> > ...\n> > @@ -3,90 +3,109 @@\n> >  test_description='test separate work tree'\n> >  . ./test-lib.sh\n> >  \n> > +i=1\n> > +\n> >  test_rev_parse() {\n> > - ...\n> > +\tname=\"$1\"\n> > +\tfor option in --is-bare-repository --is-inside-git-dir \\\n> > +\t\t--is-inside-work-tree --show-prefix\n> > +\tdo\n> > +\t\tshift\n> > +\t\ttest_expect_success \"$name: $option\" \\\n> > +\t\t\t\"test '$1' = \\\"\\$(git rev-parse $option)\\\"\"\n> \n> > +i=$(($i+1))\n> > +test $i = $STOPI && gdb --args git rev-parse $option\n> \n> Eh?\n\nYes, got me there.  It was a real PITA to debug that thing, given that the \ntests were written in the spirit of Malbolge.  So the easiest method to \ndebug it was for me to \"-i -v\" the test, run it again with \"STOPI=$n .. \n-v\", and work out what was the intended behaviour, and whether to fix the \ntest or the logic.\n\nWill clean up.\n\nCiao,\nDscho\n"}]}