Skip to content

Commit 44427a0

Browse files
committed
Merge branch 'ps/pathspec-empty-prefix-origin'
A recent update broke "git add -p ../foo" from a subdirectory. * ps/pathspec-empty-prefix-origin: pathspec: honor `PATHSPEC_PREFIX_ORIGIN` with empty prefix
2 parents da4c600 + be4dbbb commit 44427a0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

pathspec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void init_pathspec_item(struct pathspec_item *item, unsigned flags,
505505
* original. Useful for passing to another command.
506506
*/
507507
if ((flags & PATHSPEC_PREFIX_ORIGIN) &&
508-
prefixlen && !get_literal_global()) {
508+
!get_literal_global()) {
509509
struct strbuf sb = STRBUF_INIT;
510510

511511
/* Preserve the actual prefix length of each pattern */

t/t3701-add-interactive.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,28 @@ test_expect_success 'add -p handles globs' '
436436
test_cmp expect actual
437437
'
438438

439+
test_expect_success 'add -p handles relative paths' '
440+
git reset --hard &&
441+
442+
echo base >relpath.c &&
443+
git add "*.c" &&
444+
git commit -m relpath &&
445+
446+
echo change >relpath.c &&
447+
mkdir -p subdir &&
448+
git -C subdir add -p .. 2>error <<-\EOF &&
449+
y
450+
EOF
451+
452+
test_must_be_empty error &&
453+
454+
cat >expect <<-\EOF &&
455+
relpath.c
456+
EOF
457+
git diff --cached --name-only >actual &&
458+
test_cmp expect actual
459+
'
460+
439461
test_expect_success 'add -p does not expand argument lists' '
440462
git reset --hard &&
441463

0 commit comments

Comments
 (0)