Description
When stashing specific files (a file selection) and choosing Keep Staged, the staged changes are stashed away instead of being kept in the index.
This is the file-selection counterpart to #5281 — that issue's fix (c4d86fe, 18.1.0) only covered the no-selection Stash Unstaged Changes SCM group action (which passes no pathspecs).
Steps to Reproduce
- Make a staged change to a tracked file, plus a further unstaged change (or other unstaged files).
- In the Source Control view, select one or more tracked files (not all staged files).
- Stash the selection and choose Keep Staged.
- ❌ The staged change is stashed too — the index is reset instead of being kept intact.
Root Cause
stashPushCore adds --include-untracked to every pathspec push as a safety net (so a selected untracked file can be stashed). The --keep-index guard keyed off whether --include-untracked was present in the params, so it dropped --keep-index for every file-selection push — even tracked-only selections, where git's --keep-index --include-untracked -- <pathspec> bug doesn't apply.
Fix
Key the guard off the caller's actual intent (includeUntracked) instead. Tracked-only selections keep --keep-index and the index is preserved; selections that genuinely include untracked files still drop --keep-index to avoid the underlying git bug (where the restoring checkout can't match an untracked path in the index tree). That remaining untracked-in-selection case needs a fix in git itself and is tracked separately (see #5281).
GitLens Version
18.2.0 (present since 18.1.0)
Description
When stashing specific files (a file selection) and choosing Keep Staged, the staged changes are stashed away instead of being kept in the index.
This is the file-selection counterpart to #5281 — that issue's fix (c4d86fe, 18.1.0) only covered the no-selection Stash Unstaged Changes SCM group action (which passes no pathspecs).
Steps to Reproduce
Root Cause
stashPushCoreadds--include-untrackedto every pathspec push as a safety net (so a selected untracked file can be stashed). The--keep-indexguard keyed off whether--include-untrackedwas present in the params, so it dropped--keep-indexfor every file-selection push — even tracked-only selections, where git's--keep-index --include-untracked -- <pathspec>bug doesn't apply.Fix
Key the guard off the caller's actual intent (
includeUntracked) instead. Tracked-only selections keep--keep-indexand the index is preserved; selections that genuinely include untracked files still drop--keep-indexto avoid the underlying git bug (where the restoring checkout can't match an untracked path in the index tree). That remaining untracked-in-selection case needs a fix in git itself and is tracked separately (see #5281).GitLens Version
18.2.0 (present since 18.1.0)