Re: [PATCH v1] teach git to support a virtual (partially populated) work directory
From: SZEDER Gábor <hidden>
Date: 2018-11-28 13:31:21
On Tue, Nov 27, 2018 at 02:50:57PM -0500, Ben Peart wrote:
quoted hunk ↗ jump to hunk
diff --git a/t/t1092-virtualworkdir.sh b/t/t1092-virtualworkdir.sh new file mode 100755 index 0000000000..0cdfe9b362 --- /dev/null +++ b/t/t1092-virtualworkdir.sh@@ -0,0 +1,393 @@ +#!/bin/sh + +test_description='virtual work directory tests' + +. ./test-lib.sh + +# We need total control of the virtual work directory hook +sane_unset GIT_TEST_VIRTUALWORKDIR + +clean_repo () { + rm .git/index && + git -c core.virtualworkdir=false reset --hard HEAD && + git -c core.virtualworkdir=false clean -fd && + touch untracked.txt &&
We would usually run '>untracked.txt' instead, sparing the external process. A further nit is that a function called 'clean_repo' creates new untracked files...
quoted hunk ↗ jump to hunk
+ touch dir1/untracked.txt && + touch dir2/untracked.txt +} + +test_expect_success 'setup' ' + mkdir -p .git/hooks/ && + cat > .gitignore <<-\EOF &&
CodingGuidelines suggest no space between redirection operator and filename.
quoted hunk ↗ jump to hunk
+ .gitignore + expect* + actual* + EOF + touch file1.txt && + touch file2.txt && + mkdir -p dir1 && + touch dir1/file1.txt && + touch dir1/file2.txt && + mkdir -p dir2 && + touch dir2/file1.txt && + touch dir2/file2.txt && + git add . && + git commit -m "initial" && + git config --local core.virtualworkdir true +'
+test_expect_success 'verify files not listed are ignored by git clean -f -x' ' + clean_repo &&
I find it odd to clean the repo right after setting it up; but then again, 'clean_repo' not only cleans, but also creates new files. Perhaps rename it to 'reset_repo'? Dunno.
quoted hunk ↗ jump to hunk
+ write_script .git/hooks/virtual-work-dir <<-\EOF && + printf "untracked.txt\0" + printf "dir1/\0" + EOF + mkdir -p dir3 && + touch dir3/untracked.txt && + git clean -f -x && + test -f file1.txt &&
Please use the 'test_path_is_file', ...
+ test -f file2.txt && + test ! -f untracked.txt &&
... 'test_path_is_missing', and ...
+ test -d dir1 &&
... 'test_path_is_dir' helpers, respectively, because they print informative error messages on failure.
quoted hunk ↗ jump to hunk
+ test -f dir1/file1.txt && + test -f dir1/file2.txt && + test ! -f dir1/untracked.txt && + test -f dir2/file1.txt && + test -f dir2/file2.txt && + test -f dir2/untracked.txt && + test -d dir3 && + test -f dir3/untracked.txt +'