Skip to content

Commit 90f6b5a

Browse files
committed
Merge branch 'aj/stash-staged-fix'
"git stash -S" did not handle binary files correctly, which has been corrected. * aj/stash-staged-fix: stash: fix "--staged" with binary files
2 parents 708e925 + 5fb7686 commit 90f6b5a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

builtin/stash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,8 @@ static int stash_staged(struct stash_info *info, struct strbuf *out_patch,
12051205
}
12061206

12071207
cp_diff_tree.git_cmd = 1;
1208-
strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD",
1209-
oid_to_hex(&info->w_tree), "--", NULL);
1208+
strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "--binary",
1209+
"-U1", "HEAD", oid_to_hex(&info->w_tree), "--", NULL);
12101210
if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) {
12111211
ret = -1;
12121212
goto done;

t/t3903-stash.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,15 @@ test_expect_success 'stash --staged' '
393393
test bar,bar4 = $(cat file),$(cat file2)
394394
'
395395

396+
test_expect_success 'stash --staged with binary file' '
397+
printf "\0" >file &&
398+
git add file &&
399+
git stash --staged &&
400+
git stash pop &&
401+
printf "\0" >expect &&
402+
test_cmp expect file
403+
'
404+
396405
test_expect_success 'dont assume push with non-option args' '
397406
test_must_fail git stash -q drop 2>err &&
398407
test_grep -e "subcommand wasn'\''t specified; '\''push'\'' can'\''t be assumed due to unexpected token '\''drop'\''" err

0 commit comments

Comments
 (0)