Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Adam Johnson <me@adamj.eu>
To: git@vger.kernel.org
Subject: Bug: 'git stash --staged' crashes with binary files
Date: Thu, 1 Jun 2023 22:26:13 +0100	[thread overview]
Message-ID: <CAMyDDM3DFyru6zph4qqf_QoaOeezvYkT7SmwinCfJNnFsnuRjQ@mail.gmail.com> (raw)

Stage a binary file and run 'git stash --staged'. The stash is created but
the command fails to remove changes from the index:

$ echo -n "\0" >file

$ git add file

$ git stash --staged
Saved working directory and index state WIP on main: e7911b6 Whatever
error: cannot apply binary patch to 'file' without full index line
error: file: patch does not apply
Cannot remove worktree changes

$ git status
...
Changes to be committed:
        new file:   file

The "remove from the index" step seems not to be binary-compatible.

The below patch adds a reproducing test.

diff --git t/t3903-stash.sh t/t3903-stash.sh
index 376cc8f4ab..5e3ea64f38 100755
--- t/t3903-stash.sh
+++ t/t3903-stash.sh
@@ -392,6 +392,13 @@ setup_stash()
     git stash pop &&
     test bar,bar4 = $(cat file),$(cat file2)
 '
+test_expect_success 'stash --staged with binary file' '
+    echo -n "\0" >file &&
+    git add file &&
+    git stash --staged &&
+    git stash pop &&
+    test "\0" = $(cat file)
+'

 test_expect_success 'dont assume push with non-option args' '
     test_must_fail git stash -q drop 2>err &&

             reply	other threads:[~2023-06-01 21:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 21:26 Adam Johnson [this message]
2023-10-11 18:17 ` Bug: 'git stash --staged' crashes with binary files Jeff King
2023-10-11 18:23   ` rsbecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMyDDM3DFyru6zph4qqf_QoaOeezvYkT7SmwinCfJNnFsnuRjQ@mail.gmail.com \
    --to=me@adamj.eu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 read-only IMAP folder(s) and NNTP newsgroup(s).