Skip to content

Commit b1b5778

Browse files
brandb97dscho
authored andcommitted
diff: stop output garbled message in dry run mode
In dry run mode, diff_flush_patch() should not produce any output. However, in commit b55e6d3 (diff: ensure consistent diff behavior with ignore options, 2025-08-08), only the output during the comparison of two file contents was suppressed. For file deletions or mode changes, diff_flush_patch() still produces output. In run_extern_diff(), set quiet to true if in dry run mode. In emit_diff_symbol_from_struct(), directly return if in dry run mode. Signed-off-by: Lidong Yan <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9329a20 commit b1b5778

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,6 +1351,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
13511351
int len = eds->len;
13521352
unsigned flags = eds->flags;
13531353

1354+
if (o->dry_run)
1355+
return;
1356+
13541357
switch (s) {
13551358
case DIFF_SYMBOL_NO_LF_EOF:
13561359
context = diff_get_color_opt(o, DIFF_CONTEXT);
@@ -4420,7 +4423,7 @@ static void run_external_diff(const struct external_diff *pgm,
44204423
{
44214424
struct child_process cmd = CHILD_PROCESS_INIT;
44224425
struct diff_queue_struct *q = &diff_queued_diff;
4423-
int quiet = !(o->output_format & DIFF_FORMAT_PATCH);
4426+
int quiet = !(o->output_format & DIFF_FORMAT_PATCH) || o->dry_run;
44244427
int rc;
44254428

44264429
/*

t/t4013-diff-various.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,27 @@ test_expect_success 'diff -I<regex>: ignore matching file' '
661661
test_grep ! "file1" actual
662662
'
663663

664+
test_expect_success 'diff -I<regex>: ignore all content changes' '
665+
test_when_finished "git rm -f file1 file2" &&
666+
: >file1 &&
667+
git add file1 &&
668+
: >file2 &&
669+
git add file2 &&
670+
671+
rm -f file1 file2 &&
672+
mkdir file2 &&
673+
test_diff_no_content_changes () {
674+
git diff $1 --ignore-blank-lines -I".*" >actual &&
675+
test_line_count = 2 actual &&
676+
test_grep "file1" actual &&
677+
test_grep "file2" actual &&
678+
test_grep ! "diff --git" actual
679+
} &&
680+
test_diff_no_content_changes "--raw" &&
681+
test_diff_no_content_changes "--name-only" &&
682+
test_diff_no_content_changes "--name-status"
683+
'
684+
664685
# check_prefix <patch> <src> <dst>
665686
# check only lines with paths to avoid dependency on exact oid/contents
666687
check_prefix () {

0 commit comments

Comments
 (0)