@matheusbsbs / matheus-bagliano / commits / 5e568f9e30
Fork 0

Respect core.autocrlf in combined diff

Fix git-diff to make it produce useful 3-way diffs for merge conflicts in repositories with autocrlf enabled. Otherwise it always reports that the whole file was changed, because it uses the contents from the working tree without necessary conversion. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexander Gavrilov committed Aug 23, 2008 at 23:21 UTC 5e568f9e3027797842807213ce590140c9daf9ce
2 files changed +28
combine-diff.c
+12
@@ -727,6 +727,18 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
727 die("early EOF '%s'", elem->path);
728
729 result[len] = 0;
730 +
731 + /* If not a fake symlink, apply filters, e.g. autocrlf */
732 + if (is_file) {
733 + struct strbuf buf;
734 +
735 + strbuf_init(&buf, 0);
736 + if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {
737 + free(result);
738 + result = strbuf_detach(&buf, &len);
739 + result_size = len;
740 + }
741 + }
742 }
743 else {
744 deleted_file:
t/t4015-diff-whitespace.sh
+16
@@ -352,4 +352,20 @@ test_expect_success 'checkdiff allows new blank lines' '
352 git diff --check
353 '
354
355 +test_expect_success 'combined diff with autocrlf conversion' '
356 +
357 + git reset --hard &&
358 + echo >x hello &&
359 + git commit -m "one side" x &&
360 + git checkout HEAD^ &&
361 + echo >x goodbye &&
362 + git commit -m "the other side" x &&
363 + git config core.autocrlf true &&
364 + test_must_fail git merge master &&
365 +
366 + git diff | sed -e "1,/^@@@/d" >actual &&
367 + ! grep "^-" actual
368 +
369 +'
370 +
371 test_done