git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] apply: strip ./ prefix from --directory argument

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 17, 2026, 08:06 UTC
Message-ID
<aZQhnIcPa9sCPpBb@pks.im>
In-Reply-To
<pull.2198.git.git.1771002510709.gitgitgadget@gmail.com>
On Fri, Feb 13, 2026 at 05:08:30PM +0000, Joaquim Rocha via GitGitGadget wrote:
Show 8 quoted lines
> 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.

Isn't the problem wider than that though? For example, if you had "././some/sub" it would break again. Or if you had "some/./sub", or "some/sub/../sub", or "some//sub".

Show 15 quoted lines
> 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;

While this change here fixes your observed issues, the next person might run into a totally different one. So more generally, I think what we'd rather want to do is to fully normalize the path. How about this instead:

diff --git a/apply.c b/apply.c
index 9de2eb953e..8946b133a3 100644
--- a/apply.c
+++ b/apply.c
@@ -5002,6 +5002,7 @@ static int apply_option_parse_directory(const struct option *opt,
 
 	strbuf_reset(&state->root);
 	strbuf_addstr(&state->root, arg);
+	strbuf_normalize_path(&state->root);
 	strbuf_complete(&state->root, '/');
 	return 0;
 }

`strbuf_normalize_path()` drops "." components, removes ".." and it
squashes multiple directory separators. So it handles your specific use
case, but also others.

Thanks!

Patrick
Previous: Joaquim Rocha via GitGitGadgetNext: Junio C Hamano
Message 2 of 7 in “apply: strip ./ prefix from --directory argument”
  1. apply: strip ./ prefix from --directory argumentJoaquim Rocha via GitGitGadget, Feb 13, 2026
  2. Patrick SteinhardtFeb 17, 2026
  3. Junio C HamanoFeb 17, 2026
  4. Patrick SteinhardtFeb 18, 2026
  5. Joaquim RochaFeb 18, 2026
  6. apply: normalize path in --directory argumentJoaquim Rocha via GitGitGadget, Feb 18, 2026
  7. Junio C HamanoFeb 20, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.