Merge branch 'ly/diff-name-only-with-diff-from-content'

Regression fixes for a topic that has already been merged.

* ly/diff-name-only-with-diff-from-content:
  diff: stop output garbled message in dry run mode
This commit is contained in:
Junio C Hamano
2025-10-30 08:00:19 -07:00
2 changed files with 43 additions and 2 deletions

8
diff.c
View File

@@ -1351,6 +1351,9 @@ static void emit_diff_symbol_from_struct(struct diff_options *o,
int len = eds->len;
unsigned flags = eds->flags;
if (o->dry_run)
return;
switch (s) {
case DIFF_SYMBOL_NO_LF_EOF:
context = diff_get_color_opt(o, DIFF_CONTEXT);
@@ -4420,7 +4423,7 @@ static void run_external_diff(const struct external_diff *pgm,
{
struct child_process cmd = CHILD_PROCESS_INIT;
struct diff_queue_struct *q = &diff_queued_diff;
int quiet = !(o->output_format & DIFF_FORMAT_PATCH);
int quiet = !(o->output_format & DIFF_FORMAT_PATCH) || o->dry_run;
int rc;
/*
@@ -4615,7 +4618,8 @@ static void run_diff_cmd(const struct external_diff *pgm,
p->status == DIFF_STATUS_RENAMED)
o->found_changes = 1;
} else {
fprintf(o->file, "* Unmerged path %s\n", name);
if (!o->dry_run)
fprintf(o->file, "* Unmerged path %s\n", name);
o->found_changes = 1;
}
}

View File

@@ -661,6 +661,43 @@ test_expect_success 'diff -I<regex>: ignore matching file' '
test_grep ! "file1" actual
'
test_expect_success 'diff -I<regex>: ignore all content changes' '
test_when_finished "git rm -f file1 file2 file3" &&
: >file1 &&
git add file1 &&
: >file2 &&
git add file2 &&
: >file3 &&
git add file3 &&
rm -f file1 file2 &&
mkdir file2 &&
echo "A" >file3 &&
A_hash=$(git hash-object -w file3) &&
echo "B" >file3 &&
B_hash=$(git hash-object -w file3) &&
cat <<-EOF | git update-index --index-info &&
100644 $A_hash 1 file3
100644 $B_hash 2 file3
EOF
test_diff_no_content_changes () {
git diff $1 --ignore-blank-lines -I".*" >actual &&
test_line_count = 3 actual &&
test_grep "file1" actual &&
test_grep "file2" actual &&
test_grep "file3" actual &&
test_grep ! "diff --git" actual
} &&
test_diff_no_content_changes "--raw" &&
test_diff_no_content_changes "--name-only" &&
test_diff_no_content_changes "--name-status" &&
: >actual &&
test_must_fail git diff --quiet -I".*" >actual &&
test_must_be_empty actual
'
# check_prefix <patch> <src> <dst>
# check only lines with paths to avoid dependency on exact oid/contents
check_prefix () {