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

Re: [BUG] regarding `git add -p` and files containing wildcard characters

From
Jeff King <peff@peff.net>
Date
Dec 9, 2016, 05:37 UTC
Message-ID
<20161209053751.dpq3brm6pih3rc3n@sigill.intra.peff.net>
In-Reply-To
<c9876671-6252-5dfa-18df-a6719dc6834c@gmail.com>
On Fri, Dec 09, 2016 at 04:46:49AM +0300, unixway.drive@gmail.com wrote:
> The problem is that `git-diff-files` does some globbing on the 'path'
> arguments on its own and has no option to disable that (and
> `git-add--interactive`'s `run_cmd_pipe` already handles all other sorts of
> unsafe characters like spaces and backticks well).
I think the option you're looking for is:
  git --literal-pathspecs diff-files ... -- 'Random *'

I don't know if there are other commands run by add--interactive that would want the same treatment. It might actually make sense to set GIT_LITERAL_PATHSPECS=1 in the environment right after it expands the list via ls-files.

Show 15 quoted lines
> diff --git a/git-add--interactive.perl b/git-add--interactive.perl
> index ee3d812..358d877 100755
> --- a/git-add--interactive.perl
> +++ b/git-add--interactive.perl
> @@ -2,3 +2,3 @@
> 
> -use 5.008;
> +use 5.014;
>  use strict;
> @@ -761,3 +761,5 @@ sub parse_diff {
>         }
> -       my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
> +       my @diff = run_cmd_pipe("git", @diff_cmd, "--", (
> +               $path =~ s#[\[*?]#\\$&#gr
> +       ));

This callsite covers "-p". It looks like list_modified() probably needs similar treatment. Maybe others; I didn't look exhaustively.

-Peff
Previous: unixway.drive@gmail.com
Message 2 of 2 in “[BUG] regarding `git add -p` and files containing wildcard characters”
  1. unixway.drive@gmail.comDec 9, 2016
  2. Jeff KingDec 9, 2016

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.