{"thread":{"id":"27017","subject":"[PATCH 1/2] stash: add two more tests for --no-keep-index","startedAt":"2011-04-07T17:04:19Z","lastAt":"2011-04-07T17:04:20Z","messageCount":2,"participants":["Dan McGee"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"165362","messageId":"1302195860-31053-1-git-send-email-dpmcgee@gmail.com","threadId":"27017","inReplyTo":null,"subject":"[PATCH 1/2] stash: add two more tests for --no-keep-index","fromName":"Dan McGee","fromEmail":"dpmcgee@gmail.com","sentAt":"2011-04-07T17:04:19Z","receivedAt":"2011-04-07T17:04:19Z","isPatch":true,"sender":{"key":"dpmcgee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/265817?v=4"},"body":"One of these passes just fine; the other one exposes a problem where\ncommand line flag order matters for --no-keep-index and --patch\ninteraction.\n\nSigned-off-by: Dan McGee <dpmcgee@gmail.com>\n---\n t/t3903-stash.sh       |    8 ++++++++\n t/t3904-stash-patch.sh |   12 ++++++++++++\n 2 files changed, 20 insertions(+), 0 deletions(-)\n\ndiff --git a/t/t3903-stash.sh b/t/t3903-stash.sh\nindex f62aaf5..bca2df1 100755\n--- a/t/t3903-stash.sh\n+++ b/t/t3903-stash.sh\n@@ -218,6 +218,14 @@ test_expect_success 'stash -k' '\n \ttest bar,bar4 = $(cat file),$(cat file2)\n '\n \n+test_expect_success 'stash --no-keep-index' '\n+\techo bar33 > file &&\n+\techo bar44 > file2 &&\n+\tgit add file2 &&\n+\tgit stash --no-keep-index &&\n+\ttest bar,bar2 = $(cat file),$(cat file2)\n+'\n+\n test_expect_success 'stash --invalid-option' '\n \techo bar5 > file &&\n \techo bar6 > file2 &&\ndiff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh\nindex 1e7193a..4d58789 100755\n--- a/t/t3904-stash-patch.sh\n+++ b/t/t3904-stash-patch.sh\n@@ -48,6 +48,18 @@ test_expect_success PERL 'git stash -p --no-keep-index' '\n \tverify_state bar dummy bar_index\n '\n \n+test_expect_failure PERL 'git stash --no-keep-index -p' '\n+\tset_state dir/foo work index &&\n+\tset_state bar bar_work bar_index &&\n+\t(echo n; echo y) | git stash save --no-keep-index -p &&\n+\tverify_state dir/foo head head &&\n+\tverify_state bar bar_work dummy &&\n+\tgit reset --hard &&\n+\tgit stash apply --index &&\n+\tverify_state dir/foo work index &&\n+\tverify_state bar dummy bar_index\n+'\n+\n test_expect_success PERL 'none of this moved HEAD' '\n \tverify_saved_head\n '\n-- \n1.7.4.4\n"},{"id":"165363","messageId":"1302195860-31053-2-git-send-email-dpmcgee@gmail.com","threadId":"27017","inReplyTo":"1302195860-31053-1-git-send-email-dpmcgee@gmail.com","subject":"[PATCH 2/2] stash: ensure --no-keep-index and --patch can be used in any order","fromName":"Dan McGee","fromEmail":"dpmcgee@gmail.com","sentAt":"2011-04-07T17:04:20Z","receivedAt":"2011-04-07T17:04:20Z","isPatch":true,"sender":{"key":"dpmcgee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/265817?v=4"},"body":"Don't assume one comes after the other on the command line. Use a\nthree-state variable to track and check its value accordingly.\n\nSigned-off-by: Dan McGee <dpmcgee@gmail.com>\n---\n git-stash.sh           |    9 +++++----\n t/t3904-stash-patch.sh |    2 +-\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/git-stash.sh b/git-stash.sh\nindex a305fb1..fd66884 100755\n--- a/git-stash.sh\n+++ b/git-stash.sh\n@@ -136,11 +136,12 @@ save_stash () {\n \t\t\tkeep_index=t\n \t\t\t;;\n \t\t--no-keep-index)\n-\t\t\tkeep_index=\n+\t\t\tkeep_index=n\n \t\t\t;;\n \t\t-p|--patch)\n \t\t\tpatch_mode=t\n-\t\t\tkeep_index=t\n+\t\t\t# only default to keep if we don't already have an override\n+\t\t\ttest -z \"$keep_index\" && keep_index=t\n \t\t\t;;\n \t\t-q|--quiet)\n \t\t\tGIT_QUIET=t\n@@ -185,7 +186,7 @@ save_stash () {\n \tthen\n \t\tgit reset --hard ${GIT_QUIET:+-q}\n \n-\t\tif test -n \"$keep_index\" && test -n $i_tree\n+\t\tif test \"$keep_index\" = \"t\" && test -n $i_tree\n \t\tthen\n \t\t\tgit read-tree --reset -u $i_tree\n \t\tfi\n@@ -193,7 +194,7 @@ save_stash () {\n \t\tgit apply -R < \"$TMP-patch\" ||\n \t\tdie \"Cannot remove worktree changes\"\n \n-\t\tif test -z \"$keep_index\"\n+\t\tif test \"$keep_index\" != \"t\"\n \t\tthen\n \t\t\tgit reset\n \t\tfi\ndiff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh\nindex 4d58789..781fd71 100755\n--- a/t/t3904-stash-patch.sh\n+++ b/t/t3904-stash-patch.sh\n@@ -48,7 +48,7 @@ test_expect_success PERL 'git stash -p --no-keep-index' '\n \tverify_state bar dummy bar_index\n '\n \n-test_expect_failure PERL 'git stash --no-keep-index -p' '\n+test_expect_success PERL 'git stash --no-keep-index -p' '\n \tset_state dir/foo work index &&\n \tset_state bar bar_work bar_index &&\n \t(echo n; echo y) | git stash save --no-keep-index -p &&\n-- \n1.7.4.4\n"}]}