@@ -111,6 +111,19 @@ test_expect_success 'apply stashed changes' '
111111 test 1 = $(git show HEAD:file)
112112'
113113
114+ test_expect_success ' apply stashed changes with stash.index' '
115+ test_config stash.index true &&
116+ git reset --hard HEAD^ &&
117+ echo 5 >other-file &&
118+ git add other-file &&
119+ test_tick &&
120+ git commit -m other-file &&
121+ git stash apply &&
122+ test 3 = $(cat file) &&
123+ test 2 = $(git show :file) &&
124+ test 1 = $(git show HEAD:file)
125+ '
126+
114127test_expect_success ' apply stashed changes (including index)' '
115128 git reset --hard HEAD^ &&
116129 echo 6 >other-file &&
@@ -150,6 +163,21 @@ test_expect_success 'drop top stash' '
150163 test 1 = $(git show HEAD:file)
151164'
152165
166+ test_expect_success ' drop top stash with stash.index' '
167+ test_config stash.index true &&
168+ git reset --hard &&
169+ git stash list >expected &&
170+ echo 7 >file &&
171+ git stash &&
172+ git stash drop &&
173+ git stash list >actual &&
174+ test_cmp expected actual &&
175+ git stash apply &&
176+ test 3 = $(cat file) &&
177+ test 2 = $(git show :file) &&
178+ test 1 = $(git show HEAD:file)
179+ '
180+
153181test_expect_success ' drop middle stash' '
154182 git reset --hard &&
155183 echo 8 >file &&
@@ -170,6 +198,27 @@ test_expect_success 'drop middle stash' '
170198 test 1 = $(git show HEAD:file)
171199'
172200
201+ test_expect_success ' drop middle stash with stash.index' '
202+ test_config stash.index true &&
203+ git reset --hard &&
204+ echo 8 >file &&
205+ git stash &&
206+ echo 9 >file &&
207+ git stash &&
208+ git stash drop stash@{1} &&
209+ test 2 = $(git stash list | wc -l) &&
210+ git stash apply &&
211+ test 9 = $(cat file) &&
212+ test 1 = $(git show :file) &&
213+ test 1 = $(git show HEAD:file) &&
214+ git reset --hard &&
215+ git stash drop &&
216+ git stash apply &&
217+ test 3 = $(cat file) &&
218+ test 2 = $(git show :file) &&
219+ test 1 = $(git show HEAD:file)
220+ '
221+
173222test_expect_success ' drop middle stash by index' '
174223 git reset --hard &&
175224 echo 8 >file &&
@@ -236,6 +285,17 @@ test_expect_success 'stash pop' '
236285 test 0 = $(git stash list | wc -l)
237286'
238287
288+ test_expect_success ' stash pop with stash.index' '
289+ test_config stash.index true &&
290+ git reset --hard &&
291+ setup_stash &&
292+ git stash pop &&
293+ test 3 = $(cat file) &&
294+ test 2 = $(git show :file) &&
295+ test 1 = $(git show HEAD:file) &&
296+ test 0 = $(git stash list | wc -l)
297+ '
298+
239299cat > expect << EOF
240300diff --git a/file2 b/file2
241301new file mode 100644
@@ -328,6 +388,22 @@ test_expect_success 'pop -q works and is quiet' '
328388 test_must_be_empty output.out
329389'
330390
391+ test_expect_success ' pop -q works and is quiet with stash.index' '
392+ # Added file, deleted file, modified file all staged for commit
393+ echo foo >new-file &&
394+ echo test >file &&
395+ git add new-file file &&
396+ git rm other-file &&
397+ git stash &&
398+
399+ test_config stash.index true &&
400+ git stash pop -q >output.out 2>&1 &&
401+ echo test >expect &&
402+ git show :file >actual &&
403+ test_cmp expect actual &&
404+ test_must_be_empty output.out
405+ '
406+
331407test_expect_success ' pop -q --index works and is quiet' '
332408 echo foo >file &&
333409 git add file &&
@@ -1178,6 +1254,19 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
11781254 test_path_is_file bar
11791255'
11801256
1257+ test_expect_success ' stash -- <pathspec> stashes and restores the file with stash.index' '
1258+ test_config stash.index true &&
1259+ >foo &&
1260+ >bar &&
1261+ git add foo bar &&
1262+ git stash push -- foo &&
1263+ test_path_is_file bar &&
1264+ test_path_is_missing foo &&
1265+ git stash pop --no-index &&
1266+ test_path_is_file foo &&
1267+ test_path_is_file bar
1268+ '
1269+
11811270test_expect_success ' stash -- <pathspec> stashes in subdirectory' '
11821271 mkdir sub &&
11831272 >foo &&
@@ -1194,6 +1283,24 @@ test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
11941283 test_path_is_file bar
11951284'
11961285
1286+ test_expect_success ' stash -- <pathspec> stashes in subdirectory with stash.index' '
1287+ test_config stash.index true &&
1288+ rm -r sub &&
1289+ mkdir sub &&
1290+ >foo &&
1291+ >bar &&
1292+ git add foo bar &&
1293+ (
1294+ cd sub &&
1295+ git stash push -- ../foo
1296+ ) &&
1297+ test_path_is_file bar &&
1298+ test_path_is_missing foo &&
1299+ git stash pop --no-index &&
1300+ test_path_is_file foo &&
1301+ test_path_is_file bar
1302+ '
1303+
11971304test_expect_success ' stash with multiple pathspec arguments' '
11981305 >foo &&
11991306 >bar &&
@@ -1209,6 +1316,22 @@ test_expect_success 'stash with multiple pathspec arguments' '
12091316 test_path_is_file extra
12101317'
12111318
1319+ test_expect_success ' stash with multiple pathspec arguments with stash.index' '
1320+ test_config stash.index true &&
1321+ >foo &&
1322+ >bar &&
1323+ >extra &&
1324+ git add foo bar extra &&
1325+ git stash push -- foo bar &&
1326+ test_path_is_missing bar &&
1327+ test_path_is_missing foo &&
1328+ test_path_is_file extra &&
1329+ git stash pop --no-index &&
1330+ test_path_is_file foo &&
1331+ test_path_is_file bar &&
1332+ test_path_is_file extra
1333+ '
1334+
12121335test_expect_success ' stash with file including $IFS character' '
12131336 >"foo bar" &&
12141337 >foo &&
@@ -1224,6 +1347,22 @@ test_expect_success 'stash with file including $IFS character' '
12241347 test_path_is_file bar
12251348'
12261349
1350+ test_expect_success ' stash with file including $IFS character with stash.index' '
1351+ test_config stash.index true &&
1352+ >"foo bar" &&
1353+ >foo &&
1354+ >bar &&
1355+ git add foo* &&
1356+ git stash push -- "foo b*" &&
1357+ test_path_is_missing "foo bar" &&
1358+ test_path_is_file foo &&
1359+ test_path_is_file bar &&
1360+ git stash pop --no-index &&
1361+ test_path_is_file "foo bar" &&
1362+ test_path_is_file foo &&
1363+ test_path_is_file bar
1364+ '
1365+
12271366test_expect_success ' stash with pathspec matching multiple paths' '
12281367 echo original >file &&
12291368 echo original >other-file &&
@@ -1312,6 +1451,22 @@ test_expect_success 'stash without verb with pathspec' '
13121451 test_path_is_file bar
13131452'
13141453
1454+ test_expect_success ' stash without verb with pathspec with stash.index' '
1455+ test_config stash.index true &&
1456+ >"foo bar" &&
1457+ >foo &&
1458+ >bar &&
1459+ git add foo* &&
1460+ git stash -- "foo b*" &&
1461+ test_path_is_missing "foo bar" &&
1462+ test_path_is_file foo &&
1463+ test_path_is_file bar &&
1464+ git stash pop --no-index &&
1465+ test_path_is_file "foo bar" &&
1466+ test_path_is_file foo &&
1467+ test_path_is_file bar
1468+ '
1469+
13151470test_expect_success ' stash -k -- <pathspec> leaves unstaged files intact' '
13161471 git reset &&
13171472 >foo &&
0 commit comments