{"thread":{"id":"27737","subject":"[PATCH] Modify git stash tests to show failure with sparse checkouts","startedAt":"2011-06-30T19:06:38Z","lastAt":"2011-06-30T19:06:38Z","messageCount":1,"participants":["Christof Krüger"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"170724","messageId":"1309460798-17526-1-git-send-email-git@christof-krueger.de","threadId":"27737","inReplyTo":null,"subject":"[PATCH] Modify git stash tests to show failure with sparse checkouts","fromName":"Christof Krüger","fromEmail":"git@christof-krueger.de","sentAt":"2011-06-30T19:06:38Z","receivedAt":"2011-06-30T19:06:38Z","isPatch":true,"sender":{"key":"git@christof-krueger.de","avatar":null},"body":"Restoring the index from a stash doesn't respect sparse checkouts.  Tests 7\nand 16 fail.\n---\n\nI'm working on a large project using sparse-checkout. Recently, I've\nused stash apply --index for the first time and noticed that git status\nwas showing me all the files that should be hidden as deleted.\n\nUnfortunately, I don't have the time or insight to fix the problem\nmyself, so this patch only contains the modification making the test\nfail.\n\nThanks,\n  Chris\n\n t/t3903-stash.sh |  146 +++++++++++++++++++++++++++++++++++++-----------------\n 1 files changed, 101 insertions(+), 45 deletions(-)\n\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex 7197aae..29d2090 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -7,18 +7,31 @@ test_description='Test git stash'\n \n . ./test-lib.sh\n \n+check_index_for_unwanted () {\n+\ttest -z $(git diff-index HEAD --name-only|grep unwanted)\n+}\n+\n test_expect_success 'stash some dirty working directory' '\n+\techo x > unwanted &&\n+\tgit add unwanted &&\n+\ttest_tick &&\n+\tgit commit -m unwanted &&\n \techo 1 > file &&\n \tgit add file &&\n \ttest_tick &&\n \tgit commit -m initial &&\n+\tgit config core.sparsecheckout true &&\n+\techo \"*\" > .git/info/sparse-checkout &&\n+\techo \"!unwanted\" >> .git/info/sparse-checkout &&\n+\tgit read-tree -m -u HEAD &&\n \techo 2 > file &&\n \tgit add file &&\n \techo 3 > file &&\n \ttest_tick &&\n \tgit stash &&\n \tgit diff-files --quiet &&\n-\tgit diff-index --cached --quiet HEAD\n+\tgit diff-index --cached --quiet HEAD &&\n+\tcheck_index_for_unwanted\n '\n \n cat > expect << EOF\n@@ -34,13 +47,15 @@ EOF\n test_expect_success 'parents of stash' '\n \ttest $(git rev-parse stash^) = $(git rev-parse HEAD) &&\n \tgit diff stash^2..stash > output &&\n-\ttest_cmp output expect\n+\ttest_cmp output expect &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'applying bogus stash does nothing' '\n \ttest_must_fail git stash apply stash@{1} &&\n \techo 1 >expect &&\n-\ttest_cmp expect file\n+\ttest_cmp expect file &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'apply does not need clean working directory' '\n@@ -49,7 +64,8 @@ test_expect_success 'apply does not need clean working directory' '\n \techo 5 >other-file &&\n \tgit stash apply &&\n \techo 3 >expect &&\n-\ttest_cmp expect file\n+\ttest_cmp expect file &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'apply does not clobber working directory changes' '\n@@ -57,7 +73,8 @@ test_expect_success 'apply does not clobber working directory changes' '\n \techo 4 >file &&\n \ttest_must_fail git stash apply &&\n \techo 4 >expect &&\n-\ttest_cmp expect file\n+\ttest_cmp expect file &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'apply stashed changes' '\n@@ -69,7 +86,8 @@ test_expect_success 'apply stashed changes' '\n \tgit stash apply &&\n \ttest 3 = $(cat file) &&\n \ttest 1 = $(git show :file) &&\n-\ttest 1 = $(git show HEAD:file)\n+\ttest 1 = $(git show HEAD:file) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'apply stashed changes (including index)' '\n@@ -81,7 +99,8 @@ test_expect_success 'apply stashed changes (including index)' '\n \tgit stash apply --index &&\n \ttest 3 = $(cat file) &&\n \ttest 2 = $(git show :file) &&\n-\ttest 1 = $(git show HEAD:file)\n+\ttest 1 = $(git show HEAD:file) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'unstashing in a subdirectory' '\n@@ -90,7 +109,8 @@ test_expect_success 'unstashing in a subdirectory' '\n \t(\n \t\tcd subdir &&\n \t\tgit stash apply\n-\t)\n+\t) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'drop top stash' '\n@@ -104,7 +124,8 @@ test_expect_success 'drop top stash' '\n \tgit stash apply &&\n \ttest 3 = $(cat file) &&\n \ttest 1 = $(git show :file) &&\n-\ttest 1 = $(git show HEAD:file)\n+\ttest 1 = $(git show HEAD:file) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'drop middle stash' '\n@@ -124,7 +145,8 @@ test_expect_success 'drop middle stash' '\n \tgit stash apply &&\n \ttest 3 = $(cat file) &&\n \ttest 1 = $(git show :file) &&\n-\ttest 1 = $(git show HEAD:file)\n+\ttest 1 = $(git show HEAD:file) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash pop' '\n@@ -133,7 +155,8 @@ test_expect_success 'stash pop' '\n \ttest 3 = $(cat file) &&\n \ttest 1 = $(git show :file) &&\n \ttest 1 = $(git show HEAD:file) &&\n-\ttest 0 = $(git stash list | wc -l)\n+\ttest 0 = $(git stash list | wc -l) &&\n+\tcheck_index_for_unwanted\n '\n \n cat > expect << EOF\n@@ -193,39 +216,45 @@ test_expect_success 'stash branch' '\n \tgit commit -m alternate\\ second &&\n \tgit diff master..stashbranch > output &&\n \ttest_cmp output expect2 &&\n-\ttest 0 = $(git stash list | wc -l)\n+\ttest 0 = $(git stash list | wc -l) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'apply -q is quiet' '\n \techo foo > file &&\n \tgit stash &&\n \tgit stash apply -q > output.out 2>&1 &&\n-\ttest ! -s output.out\n+\ttest ! -s output.out &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'save -q is quiet' '\n \tgit stash save --quiet > output.out 2>&1 &&\n-\ttest ! -s output.out\n+\ttest ! -s output.out &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'pop -q is quiet' '\n \tgit stash pop -q > output.out 2>&1 &&\n-\ttest ! -s output.out\n+\ttest ! -s output.out &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'pop -q --index works and is quiet' '\n \techo foo > file &&\n \tgit add file &&\n \tgit stash save --quiet &&\n-\tgit stash pop -q --index > output.out 2>&1 &&\n+\tgit stash pop --index > output.out 2>&1 &&\n \ttest foo = \"$(git show :file)\" &&\n-\ttest ! -s output.out\n+\ttest ! -s output.out &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'drop -q is quiet' '\n \tgit stash &&\n \tgit stash drop -q > output.out 2>&1 &&\n-\ttest ! -s output.out\n+\ttest ! -s output.out &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash -k' '\n@@ -233,7 +262,8 @@ test_expect_success 'stash -k' '\n \techo bar4 > file2 &&\n \tgit add file2 &&\n \tgit stash -k &&\n-\ttest bar,bar4 = $(cat file),$(cat file2)\n+\ttest bar,bar4 = $(cat file),$(cat file2) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash --no-keep-index' '\n@@ -241,7 +271,8 @@ test_expect_success 'stash --no-keep-index' '\n \techo bar44 > file2 &&\n \tgit add file2 &&\n \tgit stash --no-keep-index &&\n-\ttest bar,bar2 = $(cat file),$(cat file2)\n+\ttest bar,bar2 = $(cat file),$(cat file2) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash --invalid-option' '\n@@ -252,7 +283,8 @@ test_expect_success 'stash --invalid-option' '\n \ttest_must_fail git stash save --invalid-option &&\n \ttest bar5,bar6 = $(cat file),$(cat file2) &&\n \tgit stash -- -message-starting-with-dash &&\n-\ttest bar,bar2 = $(cat file),$(cat file2)\n+\ttest bar,bar2 = $(cat file),$(cat file2) &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash an added file' '\n@@ -262,7 +294,8 @@ test_expect_success 'stash an added file' '\n \tgit stash save \"added file\" &&\n \t! test -r file3 &&\n \tgit stash apply &&\n-\ttest new = \"$(cat file3)\"\n+\ttest new = \"$(cat file3)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash rm then recreate' '\n@@ -272,7 +305,8 @@ test_expect_success 'stash rm then recreate' '\n \tgit stash save \"rm then recreate\" &&\n \ttest bar = \"$(cat file)\" &&\n \tgit stash apply &&\n-\ttest bar7 = \"$(cat file)\"\n+\ttest bar7 = \"$(cat file)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash rm and ignore' '\n@@ -284,7 +318,8 @@ test_expect_success 'stash rm and ignore' '\n \ttest file = \"$(cat .gitignore)\" &&\n \tgit stash apply &&\n \t! test -r file &&\n-\ttest file = \"$(cat .gitignore)\"\n+\ttest file = \"$(cat .gitignore)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash rm and ignore (stage .gitignore)' '\n@@ -297,7 +332,8 @@ test_expect_success 'stash rm and ignore (stage .gitignore)' '\n \t! test -r .gitignore &&\n \tgit stash apply &&\n \t! test -r file &&\n-\ttest file = \"$(cat .gitignore)\"\n+\ttest file = \"$(cat .gitignore)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success SYMLINKS 'stash file to symlink' '\n@@ -308,7 +344,8 @@ test_expect_success SYMLINKS 'stash file to symlink' '\n \ttest -f file &&\n \ttest bar = \"$(cat file)\" &&\n \tgit stash apply &&\n-\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac\n+\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '\n@@ -319,7 +356,8 @@ test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '\n \ttest -f file &&\n \ttest bar = \"$(cat file)\" &&\n \tgit stash apply &&\n-\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac\n+\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success SYMLINKS 'stash file to symlink (full stage)' '\n@@ -331,7 +369,8 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '\n \ttest -f file &&\n \ttest bar = \"$(cat file)\" &&\n \tgit stash apply &&\n-\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac\n+\tcase \"$(ls -l file)\" in *\" file -> file2\") :;; *) false;; esac &&\n+\tcheck_index_for_unwanted\n '\n \n # This test creates a commit with a symlink used for the following tests\n@@ -348,7 +387,8 @@ test_expect_success SYMLINKS 'stash symlink to file' '\n \tcase \"$(ls -l filelink)\" in *\" filelink -> file\") :;; *) false;; esac &&\n \tgit stash apply &&\n \t! test -h filelink &&\n-\ttest bar = \"$(cat file)\"\n+\ttest bar = \"$(cat file)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '\n@@ -360,7 +400,8 @@ test_expect_success SYMLINKS 'stash symlink to file (stage rm)' '\n \tcase \"$(ls -l filelink)\" in *\" filelink -> file\") :;; *) false;; esac &&\n \tgit stash apply &&\n \t! test -h filelink &&\n-\ttest bar = \"$(cat file)\"\n+\ttest bar = \"$(cat file)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success SYMLINKS 'stash symlink to file (full stage)' '\n@@ -373,7 +414,8 @@ test_expect_success SYMLINKS 'stash symlink to file (full stage)' '\n \tcase \"$(ls -l filelink)\" in *\" filelink -> file\") :;; *) false;; esac &&\n \tgit stash apply &&\n \t! test -h filelink &&\n-\ttest bar = \"$(cat file)\"\n+\ttest bar = \"$(cat file)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_failure 'stash directory to file' '\n@@ -389,7 +431,8 @@ test_expect_failure 'stash directory to file' '\n \ttest foo = \"$(cat dir/file)\" &&\n \ttest_must_fail git stash apply &&\n \ttest bar = \"$(cat dir)\" &&\n-\tgit reset --soft HEAD^\n+\tgit reset --soft HEAD^ &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_failure 'stash file to directory' '\n@@ -402,7 +445,8 @@ test_expect_failure 'stash file to directory' '\n \ttest bar = \"$(cat file)\" &&\n \tgit stash apply &&\n \ttest -f file/file &&\n-\ttest foo = \"$(cat file/file)\"\n+\ttest foo = \"$(cat file/file)\" &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash branch - no stashes on stack, stash-like argument' '\n@@ -414,7 +458,8 @@ test_expect_success 'stash branch - no stashes on stack, stash-like argument' '\n \tgit reset --hard &&\n \tgit stash branch stash-branch ${STASH_ID} &&\n \ttest_when_finished \"git reset --hard HEAD && git checkout master && git branch -D stash-branch\" &&\n-\ttest $(git ls-files --modified | wc -l) -eq 1\n+\ttest $(git ls-files --modified | wc -l) -eq 1 &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash branch - stashes on stack, stash-like argument' '\n@@ -429,7 +474,8 @@ test_expect_success 'stash branch - stashes on stack, stash-like argument' '\n \tgit reset --hard &&\n \tgit stash branch stash-branch ${STASH_ID} &&\n \ttest_when_finished \"git reset --hard HEAD && git checkout master && git branch -D stash-branch\" &&\n-\ttest $(git ls-files --modified | wc -l) -eq 1\n+\ttest $(git ls-files --modified | wc -l) -eq 1 &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash show - stashes on stack, stash-like argument' '\n@@ -447,7 +493,8 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' '\n \t 1 files changed, 1 insertions(+), 0 deletions(-)\n \tEOF\n \tgit stash show ${STASH_ID} >actual &&\n-\ttest_cmp expected actual\n+\ttest_cmp expected actual &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash show -p - stashes on stack, stash-like argument' '\n@@ -470,7 +517,8 @@ test_expect_success 'stash show -p - stashes on stack, stash-like argument' '\n \t+bar\n \tEOF\n \tgit stash show -p ${STASH_ID} >actual &&\n-\ttest_cmp expected actual\n+\ttest_cmp expected actual &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash show - no stashes on stack, stash-like argument' '\n@@ -485,7 +533,8 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' '\n \t 1 files changed, 1 insertions(+), 0 deletions(-)\n \tEOF\n \tgit stash show ${STASH_ID} >actual &&\n-\ttest_cmp expected actual\n+\ttest_cmp expected actual &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '\n@@ -505,7 +554,8 @@ test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '\n \t+foo\n \tEOF\n \tgit stash show -p ${STASH_ID} >actual &&\n-\ttest_cmp expected actual\n+\ttest_cmp expected actual &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash drop - fail early if specified stash is not a stash reference' '\n@@ -519,7 +569,8 @@ test_expect_success 'stash drop - fail early if specified stash is not a stash r\n \ttest_must_fail git stash drop $(git rev-parse stash@{0}) &&\n \tgit stash pop &&\n \ttest bar = \"$(cat file)\" &&\n-\tgit reset --hard HEAD\n+\tgit reset --hard HEAD &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash pop - fail early if specified stash is not a stash reference' '\n@@ -533,7 +584,8 @@ test_expect_success 'stash pop - fail early if specified stash is not a stash re\n \ttest_must_fail git stash pop $(git rev-parse stash@{0}) &&\n \tgit stash pop &&\n \ttest bar = \"$(cat file)\" &&\n-\tgit reset --hard HEAD\n+\tgit reset --hard HEAD &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'ref with non-existent reflog' '\n@@ -553,7 +605,8 @@ test_expect_success 'ref with non-existent reflog' '\n \ttest_must_fail git stash show does-not-exist@{0} &&\n \ttest_must_fail git stash branch tmp does-not-exist &&\n \ttest_must_fail git stash branch tmp does-not-exist@{0} &&\n-\tgit stash drop\n+\tgit stash drop &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'invalid ref of the form stash@{n}, n >= N' '\n@@ -568,7 +621,8 @@ test_expect_success 'invalid ref of the form stash@{n}, n >= N' '\n \ttest_must_fail git stash apply stash@{1} &&\n \ttest_must_fail git stash show stash@{1} &&\n \ttest_must_fail git stash branch tmp stash@{1} &&\n-\tgit stash drop\n+\tgit stash drop &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash branch should not drop the stash if the branch exists' '\n@@ -579,7 +633,8 @@ test_expect_success 'stash branch should not drop the stash if the branch exists\n \techo bar >file &&\n \tgit stash &&\n \ttest_must_fail git stash branch master stash@{0} &&\n-\tgit rev-parse stash@{0} --\n+\tgit rev-parse stash@{0} -- &&\n+\tcheck_index_for_unwanted\n '\n \n test_expect_success 'stash apply shows status same as git status (relative to current directory)' '\n@@ -598,7 +653,8 @@ test_expect_success 'stash apply shows status same as git status (relative to cu\n \t\tgit stash apply\n \t) |\n \tsed -e 1,2d >actual && # drop \"Saved...\" and \"HEAD is now...\"\n-\ttest_cmp expect actual\n+\ttest_cmp expect actual &&\n+\tcheck_index_for_unwanted\n '\n \n test_done\n-- \n1.7.6.rc3.2.g94021\n"}]}