public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] apply: strip ./ prefix from --directory argument
@ 2026-02-13 17:08 Joaquim Rocha via GitGitGadget
  2026-02-17  8:06 ` Patrick Steinhardt
  2026-02-18  0:15 ` [PATCH v2] apply: normalize path in " Joaquim Rocha via GitGitGadget
  0 siblings, 2 replies; 7+ messages in thread
From: Joaquim Rocha via GitGitGadget @ 2026-02-13 17:08 UTC (permalink / raw)
  To: git; +Cc: Joaquim Rocha, Joaquim Rocha

From: Joaquim Rocha <joaquim@amutable.com>

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>
---
    apply: strip ./ prefix from --directory argument

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2198%2Fjoaquimrocha%2Fapply-directory-dot-slash-prefix-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2198/joaquimrocha/apply-directory-dot-slash-prefix-v1
Pull-Request: https://github.com/git/git/pull/2198

 apply.c               | 4 ++++
 t/t4128-apply-root.sh | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/apply.c b/apply.c
index 3de4aa4d2e..a44c54077c 100644
--- a/apply.c
+++ b/apply.c
@@ -5001,6 +5001,10 @@ static int apply_option_parse_directory(const struct option *opt,
 	BUG_ON_OPT_NEG(unset);
 
 	strbuf_reset(&state->root);
+
+	if (starts_with(arg, "./"))
+		arg += 2;
+
 	strbuf_addstr(&state->root, arg);
 	strbuf_complete(&state->root, '/');
 	return 0;
diff --git a/t/t4128-apply-root.sh b/t/t4128-apply-root.sh
index f6db5a79dd..2f446a4d69 100755
--- a/t/t4128-apply-root.sh
+++ b/t/t4128-apply-root.sh
@@ -43,6 +43,15 @@ test_expect_success 'apply --directory -p (2) ' '
 
 '
 
+test_expect_success 'apply --directory (./ prefix)' '
+	git reset --hard initial &&
+	git apply --directory=./some/sub -p3 --index patch &&
+	echo Bello >expect &&
+	git show :some/sub/dir/file >actual &&
+	test_cmp expect actual &&
+	test_cmp expect some/sub/dir/file
+'
+
 cat > patch << EOF
 diff --git a/newfile b/newfile
 new file mode 100644

base-commit: 6fcee4785280a08e7f271bd015a4dc33753e2886
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-02-20 20:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-13 17:08 [PATCH] apply: strip ./ prefix from --directory argument Joaquim Rocha via GitGitGadget
2026-02-17  8:06 ` Patrick Steinhardt
2026-02-17 20:27   ` Junio C Hamano
2026-02-18 14:14     ` Patrick Steinhardt
2026-02-18 14:40       ` Joaquim Rocha
2026-02-18  0:15 ` [PATCH v2] apply: normalize path in " Joaquim Rocha via GitGitGadget
2026-02-20 20:26   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox