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

Re: [Bug report] diff.noprefix config is ignored for interactive `add`

From
Jeff King <peff@peff.net>
Date
Apr 6, 2021, 21:36 UTC
Message-ID
<YGzUerPL7V8jDxHo@coredump.intra.peff.net>
In-Reply-To
<CAMJzOtyzu8y5mWdKXe3MPe8ZoJs8O=me8Xuu0t77YVdAMc7Tgg@mail.gmail.com>
On Tue, Apr 06, 2021 at 12:15:28PM +0200, Nikita Bobko wrote:
Show 9 quoted lines
> Steps to reproduce:
> 1. Run `git -c diff.noprefix=true add -p`
> 
> Expected behavior:
> `a/` and `b/` prefixes are not shown during interactive `add`
> like this:
> [...]
> Actual behavior:
> `a/` and `b/` prefixes are shown instead. Like this:

That's not too surprising. The add-interactive script is built around the diff-tree plumbing command, which does not respect a lot of "cosmetic" config, especially if it would make the diff hard to parse. So the add-interactive command would have to manually plumb through the config option, like we do for some other options.

In this case, I think you'd want to enable the option only for the version of the diff we show to the user (since the machine-readable one has to actually be parsed by git-apply). This is what we do for supporting color diffs, for example.

I imagine something like this:
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index bc3a1e8eff..1a249e15cb 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -43,6 +43,12 @@
 		$repo->get_color('color.diff.new', 'green'),
 	) : ();
 
+# options to feed to diff to produce human-readable version
+my @human_diff_opts = (
+	$diff_use_color ? '--color' : (),
+	$repo->config_bool('diff.noprefix') ? qw(--no-prefix) : (),
+);
+
 my $normal_color = $repo->get_color("", "reset");
 
 my $diff_algorithm = $repo->config('diff.algorithm');
@@ -714,8 +720,8 @@ sub parse_diff {
 	}
 	my @diff = run_cmd_pipe("git", @diff_cmd, qw(--no-color --), $path);
 	my @colored = ();
-	if ($diff_use_color) {
-		my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);
+	if (@human_diff_opts) {
+		my @display_cmd = ("git", @diff_cmd, @human_diff_opts, '--', $path);
 		if (defined $diff_filter) {
 			# quotemeta is overkill, but sufficient for shell-quoting
 			my $diff = join(' ', map { quotemeta } @display_cmd);

would work, but I didn't really test it. There's another hitch, which is
that this subsystem has all been re-written in C. So we'd really want to
implement it in the new code (possibly in both places, though maybe it
is time to consider cutting over from the perl script to the C one by
deafult?).

But hopefully this illustrates the general idea, and gives somebody
interested in the feature enough to work up their own patch.

-Peff
Previous: Nikita BobkoNext: Junio C Hamano
Message 2 of 4 in “[Bug report] diff.noprefix config is ignored for interactive `add`”
  1. Nikita BobkoApr 6, 2021
  2. Jeff KingApr 6, 2021
  3. Junio C HamanoApr 6, 2021
  4. Jeff KingApr 6, 2021

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.