Skip to content

Commit 82e24c3

Browse files
committed
apply: strip ./ prefix from --directory argument
When passing a relative path like --directory=./some/sub, the leading "./" caused apply to prepend it literally to patch filenames, resulting in an error (invalid path). Since using "./" is almost memory muscle for many, strip the "./" prefix so it behaves the same as --directory=some/sub. Signed-off-by: Joaquim Rocha <joaquim@amutable.com>
1 parent 6fcee47 commit 82e24c3

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

apply.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5001,6 +5001,10 @@ static int apply_option_parse_directory(const struct option *opt,
50015001
BUG_ON_OPT_NEG(unset);
50025002

50035003
strbuf_reset(&state->root);
5004+
5005+
if (starts_with(arg, "./"))
5006+
arg += 2;
5007+
50045008
strbuf_addstr(&state->root, arg);
50055009
strbuf_complete(&state->root, '/');
50065010
return 0;

t/t4128-apply-root.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ test_expect_success 'apply --directory -p (2) ' '
4343
4444
'
4545

46+
test_expect_success 'apply --directory (./ prefix)' '
47+
git reset --hard initial &&
48+
git apply --directory=./some/sub -p3 --index patch &&
49+
echo Bello >expect &&
50+
git show :some/sub/dir/file >actual &&
51+
test_cmp expect actual &&
52+
test_cmp expect some/sub/dir/file
53+
'
54+
4655
cat > patch << EOF
4756
diff --git a/newfile b/newfile
4857
new file mode 100644

0 commit comments

Comments
 (0)