git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* "git-stash --keep-index" crashes when there are no tracked files
@ 2024-08-13 17:36 Piotr Siupa
  2024-08-16 10:39 ` Patrick Steinhardt
  2024-08-16 10:42 ` [PATCH] builtin/stash: fix `--keep-index --include-untracked` with empty HEAD Patrick Steinhardt
  0 siblings, 2 replies; 3+ messages in thread
From: Piotr Siupa @ 2024-08-13 17:36 UTC (permalink / raw)
  To: git

Hello,

I've found a bug.
It's something that's unlikely to happen in a normal workflow but it
breaks a script I'm trying to write.

Here is the complete report from "git bugreport":

Thank you for filling out a Git bug report!
Please answer the following questions to help us understand your issue.

What did you do before the bug happened? (Steps to reproduce your issue)
git init
git commit --allow-empty --message='initial commit'
touch foo
git stash push --include-untracked --keep-index

What did you expect to happen? (Expected behavior)
A stash entry storing the untracked file "foo" should be created. The
working directory and index should become empty.

What happened instead? (Actual behavior)
The command did what was expected but after that it crashed with the
following error message:
error: pathspec ':/' did not match any file(s) known to git

What's different between what you expected and what actually happened?
There should be no error message and the exit code should be 0.

Anything else you want to add:
This happens only if there are no files in the current HEAD. Adding
any file to the initial commit prevents the error from occurring (even
if it is unchanged when the stash is created).
I suspect that the command has trouble with the corner case of
restoring the state of the index when there are no tracked files.
I also tested it using executables of "git-stash" compiled from
current branches "maint" and "next". The behavior is the same.

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.34.1
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 6.8.0-39-generic #39~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC
Wed Jul 10 15:35:09 UTC 2 x86_64
compiler info: gnuc: 11.4
libc info: glibc: 2.35
$SHELL (typically, interactive shell): /bin/bash


[Enabled Hooks]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-16 10:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 17:36 "git-stash --keep-index" crashes when there are no tracked files Piotr Siupa
2024-08-16 10:39 ` Patrick Steinhardt
2024-08-16 10:42 ` [PATCH] builtin/stash: fix `--keep-index --include-untracked` with empty HEAD Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).