Skip to content

Commit 7b30c3a

Browse files
rscharfegitster
authored andcommitted
diff: report unmerged paths as changes in run_diff_cmd()
You can ask the diff machinery to let the exit code indicate whether there are changes, e.g. with --quiet. It as two ways to calculate that bit: The quick one assumes blobs with different hashes have different content, and the more elaborate way actually compares the contents, possibly applying transformations like ignoring whitespace. The quick way considers an unmerged file to be a change and reports exit code 1, which makes sense. The slower path uses the struct diff_options member found_changes to indicate whether the blobs differ even with the transformations applied. It's not set for unmerged files, though, resulting in exit code 0. Set found_changes in run_diff_cmd() for unmerged files, for a consistent exit code of 1 if there's an unmerged file, regardless of whether whitespace is ignored. Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 7b30c3a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,6 +4547,7 @@ static void run_diff_cmd(const char *pgm,
45474547
o, complete_rewrite);
45484548
} else {
45494549
fprintf(o->file, "* Unmerged path %s\n", name);
4550+
o->found_changes = 1;
45504551
}
45514552
}
45524553

t/t4046-diff-unmerged.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,12 @@ test_expect_success 'diff --stat' '
9696
test_cmp diff-stat.expect diff-stat.actual
9797
'
9898

99+
test_expect_success 'diff --quiet' '
100+
test_expect_code 1 git diff --cached --quiet
101+
'
102+
103+
test_expect_success 'diff --quiet --ignore-all-space' '
104+
test_expect_code 1 git diff --cached --quiet --ignore-all-space
105+
'
106+
99107
test_done

0 commit comments

Comments
 (0)