]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/stash: fix `--keep-index --include-untracked` with empty HEAD
authorPatrick Steinhardt <ps@pks.im>
Fri, 16 Aug 2024 10:42:25 +0000 (12:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 16 Aug 2024 16:50:33 +0000 (09:50 -0700)
commite3209bd4df1f609fb2d730e52d3eea0633dbd786
treef55010a3359f6ef4024eb360013f0267398d554e
parentdbecc617f75eea6ee5d05823a38b91223ff22b11
builtin/stash: fix `--keep-index --include-untracked` with empty HEAD

It was reported that creating a stash with `--keep-index
--include-untracked` causes an error when HEAD points to a commit whose
tree is empty:

    $ git stash push --keep-index --include-untracked
    error: pathspec ':/' did not match any file(s) known to git

This error comes from `git checkout --no-overlay $i_tree -- :/`, which
we execute to reset the working tree to the state in our index. As the
tree generated from the index is empty in our case, ':/' does not match
any files and thus causes git-checkout(1) to error out.

Fix the issue by skipping the checkout when the index tree is empty. As
explained in the in-code comment, this should be the correct thing to do
as there is nothing that we'd have to reset in the first place.

Reported-by: Piotr Siupa <piotrsiupa@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/stash.c
t/t3903-stash.sh