{"thread":{"id":"36608","subject":"unexpected behaviour for \"git diff --word-diff\"","startedAt":"2014-05-08T16:39:49Z","lastAt":"2014-05-08T16:39:49Z","messageCount":1,"participants":["ovhrb6ho1pnnv7lo@mailinator.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"241009","messageId":"20140508163949.GA1801@else-banjo.ktb.de","threadId":"36608","inReplyTo":null,"subject":"unexpected behaviour for \"git diff --word-diff\"","fromName":"","fromEmail":"ovhrb6ho1pnnv7lo@mailinator.com","sentAt":"2014-05-08T16:39:49Z","receivedAt":"2014-05-08T16:39:49Z","isPatch":false,"sender":{"key":"ovhrb6ho1pnnv7lo@mailinator.com","avatar":null},"body":"Hi,\n\nI get an unexpected behaviour for \"git diff --word-diff\" if 2 adjacent lines\nstart and end with the same letter. I tried versions 1.7.9 and 1.9.0.\n\nAttached is a script with 7 examples. For each example, a file with 2 lines is\ncompared to a file with the same lines, only 1 or 2 letters appended in each\nline. Each example is executed 4 times: with and without --word-diff-regex=.,\nand with and without -R. The script prints the result of the diff of the 2\nfiles. Just below it also prints the result of a counterexample: the same 2\nlines with 2 lines (1 was sometimes not enough) of \"xxx\" between them.\n\nOnly for tests 5c,d and 6c,d the result matches the result for the\ncounterexample.\n\nKind regards,\nThomas\n\n\n#!/bin/bash\n\n##########################################\n# execute 6 tests with counterexamples for \"git diff --word-diff\"\n#\n# (optional) argument: (sub-)test to execute, e.g. \"1\" or \"3b\"\n#   if none/empty: all tests are executed\n#\n# common header lines of the diff output are removed\n##########################################\n\n# init global variables:\n#   command to execute\nGITDIFF=\"git diff --word-diff=plain --no-index --no-color\"\n#   names of test files\nfile1=$0.1\nfile2=$0.2\nfile1x=$0.1x\nfile2x=$0.2x\n#   wanted test case, info to print\nwant=\ninfo=\n\n##########################################\n# do_sub_test()\n#   call \"git diff\" for a sub-test and its counterexample\n#   common header lines of the diff output are removed\ndo_sub_test() {\n    curr_sub_test=$1\n\n    # set additional arguments for git diff\n    case $curr_sub_test in\n        *a) add_args=;;\n        *b) add_args=-R;;\n        *c) add_args=--word-diff-regex=.;;\n        *d) add_args=\"-R --word-diff-regex=.\";;\n    esac\n\n    # execute original test\n    echo \"  -- test\" $curr_sub_test: DIFF $add_args: $info\n    $GITDIFF $add_args $file1 $file2 | sed '/^[di+-]\\|^@@ -1,2 +1,2 /d'\n\n    # execute counterexample\n    echo \"    -- expected:\"\n    $GITDIFF $add_args $file1x $file2x | sed '/^[di+-]\\|^xxx$\\|^@@ -1,4 +1,4 /d'\n}\n\n##########################################\n# do_test()\n#   create files for a test, call do_sub_test for wanted sub-test (or all)\ndo_test() {\n    curr_test=$1\n    line1=$2\n    line2=$3\n    append=$4\n\n    # create files for test\n    echo -e \"$line1\\n$line2\" > $file1\n    echo -e \"$line1$append\\n$line2$append\" > $file2\n\n    # create files for counterexample\n    echo -e \"$line1\\nxxx\\nxxx\\n$line2\" > $file1x\n    echo -e \"$line1$append\\nxxx\\nxxx\\n$line2$append\" > $file2x\n\n    info=\"append '$append' to '$line1' <nl> '$line2'\"\n\n    # call do_sub_test for wanted sub-test (or all)\n    case $want in ?a|?|'') do_sub_test ${curr_test}a;; esac\n    case $want in ?b|?|'') do_sub_test ${curr_test}b;; esac\n    case $want in ?c|?|'') do_sub_test ${curr_test}c;; esac\n    case $want in ?d|?|'') do_sub_test ${curr_test}d;; esac\n}\n\n##########################################\n# do_all_tests()\n#   call do_test for wanted test (or all)\ndo_all_tests() {\n    want=$1\n\n    case $want in 1*|'') do_test 1 '' .a .   ;; esac\n    case $want in 2*|'') do_test 2 .  .a .   ;; esac\n    case $want in 3*|'') do_test 3 '' a  a   ;; esac\n    case $want in 4*|'') do_test 4 a  aa a   ;; esac\n    case $want in 5*|'') do_test 5 '' a  b   ;; esac\n    case $want in 6*|'') do_test 6 '' a  'b ';; esac\n}\n\n##########################################\n# main()\n#   prepare cleanup, do tests\n\n# clean up test files on exit and some signals\ntrap \"rm -f $file1 $file2 $file1x $file2x; exit\" 0 1 2 15\n\nusage=\"Usage: $0 [<testcase>]\\n  <testcase> can be [1-6][a-d] or empty\\n  e.g. '$0 1' or '$0 3b'\"\n\ncase $1 in\n    [1-6]|[1-6][a-d]|'')\n    ;;\n\n    -h|--help)\n        echo -e $usage\n        exit\n    ;;\n\n    *)\n        echo -e \"Error: invalid argument '$1'\\n$usage\"\n        exit\n    ;;\nesac\n\n# do tests\ndo_all_tests $1\n"}]}