Merge branch 'dk/stash-apply-index'

The stash.index configuration variable can be set to make "git stash
pop/apply" pretend that it was invoked with "--index".

* dk/stash-apply-index:
  stash: honor stash.index in apply, pop modes
  stash: refactor private config globals
  t3905: remove unneeded blank line
  t3903: reduce dependencies on previous tests
This commit is contained in:
Junio C Hamano
2025-09-29 11:40:35 -07:00
4 changed files with 56 additions and 7 deletions

View File

@@ -902,6 +902,7 @@ test_expect_success 'branch: should not drop the stash if the apply fails' '
test_expect_success 'apply: show same status as git status (relative to ./)' '
git stash clear &&
mkdir -p subdir &&
echo 1 >subdir/subfile1 &&
echo 2 >subdir/subfile2 &&
git add subdir/subfile1 &&
@@ -1356,6 +1357,7 @@ test_expect_success 'stash -k -- <pathspec> leaves unstaged files intact' '
test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' '
git reset &&
mkdir -p subdir &&
>subdir/untracked &&
>subdir/tracked1 &&
>subdir/tracked2 &&
@@ -1372,6 +1374,7 @@ test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact'
test_expect_success 'stash -- <subdir> works with binary files' '
git reset &&
mkdir -p subdir &&
>subdir/untracked &&
>subdir/tracked &&
cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary &&
@@ -1750,4 +1753,41 @@ test_expect_success 'controlled error return on unrecognized option' '
grep -e "^usage: git stash show" usage
'
test_expect_success 'stash.index=true implies --index' '
# setup for a few related tests
test_commit file base &&
echo index >file &&
git add file &&
echo working >file &&
git stash &&
test_when_finished "git reset --hard" &&
git -c stash.index=true stash apply &&
echo index >expect &&
git show :0:file >actual &&
test_cmp expect actual &&
echo working >expect &&
test_cmp expect file
'
test_expect_success 'stash.index=true overridden by --no-index' '
test_when_finished "git reset --hard" &&
git -c stash.index=true stash apply --no-index &&
echo base >expect &&
git show :0:file >actual &&
test_cmp expect actual &&
echo working >expect &&
test_cmp expect file
'
test_expect_success 'stash.index=false overridden by --index' '
test_when_finished "git reset --hard" &&
git -c stash.index=false stash apply --index &&
echo index >expect &&
git show :0:file >actual &&
test_cmp expect actual &&
echo working >expect &&
test_cmp expect file
'
test_done

View File

@@ -87,7 +87,6 @@ test_expect_success 'stash save --patch --all fails' '
test_expect_success 'clean up untracked/untracked file to prepare for next tests' '
git clean --force --quiet
'
test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '