]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'aj/stash-staged-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Apr 2024 21:49:43 +0000 (14:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Apr 2024 21:49:43 +0000 (14:49 -0700)
"git stash -S" did not handle binary files correctly, which has
been corrected.

* aj/stash-staged-fix:
  stash: fix "--staged" with binary files

builtin/stash.c
t/t3903-stash.sh

index 062be1fbc07b0c2ecfcc6f41f5d995ae13c0aecb..7751bca868eee97672cd9c1c31674bde3f7ab6b1 100644 (file)
@@ -1205,8 +1205,8 @@ static int stash_staged(struct stash_info *info, struct strbuf *out_patch,
        }
 
        cp_diff_tree.git_cmd = 1;
-       strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD",
-                    oid_to_hex(&info->w_tree), "--", NULL);
+       strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "--binary",
+                    "-U1", "HEAD", oid_to_hex(&info->w_tree), "--", NULL);
        if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) {
                ret = -1;
                goto done;
index 00db82fb2455b8397de6ae0e5ea8e4fd96ed3d6c..a7f71f8126fce48ef58e32d89f628a91bf234899 100755 (executable)
@@ -393,6 +393,15 @@ test_expect_success 'stash --staged' '
        test bar,bar4 = $(cat file),$(cat file2)
 '
 
+test_expect_success 'stash --staged with binary file' '
+       printf "\0" >file &&
+       git add file &&
+       git stash --staged &&
+       git stash pop &&
+       printf "\0" >expect &&
+       test_cmp expect file
+'
+
 test_expect_success 'dont assume push with non-option args' '
        test_must_fail git stash -q drop 2>err &&
        test_grep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err