Skip to content

Commit 3b87291

Browse files
committed
Merge remote-tracking branch 'dscho/add-p' into add-p-g4w
Let's test this for a while. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 1286eaf + 21dd6ae commit 3b87291

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

builtin/add.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ static struct option builtin_add_options[] = {
345345
N_("backend for `git stash -p`")),
346346
OPT_PATHSPEC_FROM_FILE(&pathspec_from_file),
347347
OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul),
348+
OPT_HIDDEN_BOOL(0, "legacy-stash-p", &legacy_stash_p,
349+
N_("backend for `git stash -p`")),
348350
OPT_END(),
349351
};
350352

@@ -459,6 +461,18 @@ int cmd_add(int argc, const char **argv, const char *prefix)
459461
return run_add_interactive(NULL, "--patch=stash", &pathspec);
460462
}
461463

464+
if (legacy_stash_p) {
465+
struct pathspec pathspec;
466+
467+
parse_pathspec(&pathspec, 0,
468+
PATHSPEC_PREFER_FULL |
469+
PATHSPEC_SYMLINK_LEADING_PATH |
470+
PATHSPEC_PREFIX_ORIGIN,
471+
prefix, argv);
472+
473+
return run_add_interactive(NULL, "--patch=stash", &pathspec);
474+
}
475+
462476
if (edit_interactive) {
463477
if (pathspec_from_file)
464478
die(_("--pathspec-from-file is incompatible with --edit"));

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps,
10371037
}
10381038

10391039
cp_diff_tree.git_cmd = 1;
1040-
argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "HEAD",
1040+
argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD",
10411041
oid_to_hex(&info->w_tree), "--", NULL);
10421042
if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) {
10431043
ret = -1;

git-legacy-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ create_stash () {
213213
w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||
214214
die "$(gettext "Cannot save the current worktree state")"
215215

216-
git diff-tree -p HEAD $w_tree -- >"$TMP-patch" &&
216+
git diff-tree -p -U1 HEAD $w_tree -- >"$TMP-patch" &&
217217
test -s "$TMP-patch" ||
218218
die "$(gettext "No changes selected")"
219219

t/t3904-stash-patch.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ test_expect_success 'none of this moved HEAD' '
8989
verify_saved_head
9090
'
9191

92-
test_expect_failure 'stash -p with split hunk' '
92+
test_expect_success 'stash -p with split hunk' '
9393
git reset --hard &&
9494
cat >test <<-\EOF &&
9595
aaa
@@ -106,8 +106,8 @@ test_expect_failure 'stash -p with split hunk' '
106106
ccc
107107
EOF
108108
printf "%s\n" s n y q |
109-
test_might_fail git stash -p 2>error &&
110-
! test_must_be_empty error &&
109+
git stash -p 2>error &&
110+
test_must_be_empty error &&
111111
grep "added line 1" test &&
112112
! grep "added line 2" test
113113
'

0 commit comments

Comments
 (0)