Also add t/ which some tests and examples.
# Detect copies and renames.
renames = copy
+ # Change the definition of a word as used by diff --color-words to be
+ # shorter (not only spaces) and thus simplify the generated diffs.
+ # Words ([a-zA-Z0-9_]+) are matched, or a single non-word character
+ # ([^a-zA-Z0-9_]), therefore changes to words are shown in complete
+ # (e.g. from "word" to "newword" as "[-word-]{+newword+}"), but
+ # changes to non-word characters are shown character wise (e.g. from
+ # "==" to "!=" as "[-=-]{+!+}="); [-..-] is removal, {+..+} is
+ # addition. See t/ for some tests and examples.
+ wordregex = [a-zA-Z0-9_]+|[^a-zA-Z0-9_]
+
# Allow diffing of some binary files.
# `pdftotext-` is a wrapper around pdftotext which writes to stdout.
# `sqlite3dump` is a wrapper calling `sqlite3 database-file .dump`.
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+====
+
+Short sentence with words!
+
+Longer sentence even more words, ain't that nice!
+
+And other one, just testing.
+
+option: new value
+option-two: new-value-two
+option-three: "value-three"
+
+function testme() {
+ firstCall();
+ while (a != b) {
+ if (!second_var) {
+ third_call() && fourth_call() \
+ || fifth_call();
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+[-=====-]{+====+}
+
+[-Simple-]{+Short+} sentence with [-a few words.-]{+words!+}
+
+Longer sentence[-with-] even more [-words ..-]{+words,+} ain't that [-nice?-]{+nice!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new+} value
+option-two: [-value-two-]{+new-value-two+}
+option-three: [-value-three-]{+"value-three"+}
+
+function testme() {
+ [-first_call();-]
+[- if-]{+firstCall();+}
+{+ while+} (a [-==-]{+!=+} b) {
+ if [-(!second_call())-]{+(!second_var)+} {
+ [-third_call();-]{+third_call() && fourth_call() \+}
+{+ || fifth_call();+}
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+====[-=-]
+
+S[-imple-]{+hort+} sentence with [-a few -]words[-.-]{+!+}
+
+Longer sentence [-with -]even more words[- ..-]{+,+} ain't that nice[-?-]{+!+}
+
+And [-an-]other one, just testing.
+
+option: {+new +}value
+option-two: {+new-+}value-two
+option-three: {+"+}value-three{+"+}
+
+function testme() {
+ first[-_c-]{+C+}all();
+ {+wh+}i[-f-]{+le+} (a [-=-]{+!+}= b) {
+ if (!second_{+var) {+}
+{+ third_+}call(){+ && fourth_call(+}) [-{-]{+\+}
+{+ +} {+|| fif+}th[-ird-]_call();
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+====[-=-]
+
+[-Simple-]{+Short+} sentence with [-a few -]words[-.-]{+!+}
+
+Longer sentence [-with -]even more words[- ..-]{+,+} ain't that nice[-?-]{+!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new +}value
+option-two: {+new-+}value-two
+option-three: {+"+}value-three{+"+}
+
+function testme() {
+ [-first_call-]{+firstCall+}();
+ [-if-]{+while+} (a [-=-]{+!+}= b) {
+ if (![-second_call()-]{+second_var+}) {
+ third_call(){+ && fourth_call() \+}
+{+ || fifth_call()+};
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+[-=====-]{+====+}
+
+[-Simple-]{+Short+} sentence with [-a few -]words[-.-]{+!+}
+
+Longer sentence [-with -]even more words[- .. -]{+, +}ain't that nice[-?-]{+!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new +}value
+option-two: {+new-+}value-two
+option-three[-: -]{+: "+}value-three{+"+}
+
+function testme() {
+ [-first_call-]{+firstCall+}();
+ [-if-]{+while+} (a[- == -]{+ != +}b) {
+ if (![-second_call()) {-]{+second_var) {+}
+ third_call{+() && fourth_call() \+}
+{+ || fifth_call+}();
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+[-=====-]{+====+}
+
+[-Simple-]{+Short+} sentence with [-a few -]words[-.-]{+!+}
+
+Longer sentence [-with -]even more words[- .. -]{+, +}ain't that nice[-?-]{+!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new +}value
+option-two: {+new-+}value-two
+option-three[-: -]{+: "+}value-three{+"+}
+
+function testme() {
+ [-first_call-]{+firstCall+}();
+ [-if-]{+while+} (a[- == -]{+ != +}b) {
+ if (![-second_call()) {-]{+second_var) {+}
+ third_call{+() && fourth_call() \+}
+{+ || fifth_call+}();
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+[-=====-]{+====+}
+
+[-Simple-]{+Short+} sentence with [-a few -]words[-.-]{+!+}
+
+Longer sentence [-with -]even more words[- ..-]{+,+} ain't that nice[-?-]{+!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new +}value
+option-two: {+new-+}value-two
+option-three: {+"+}value-three{+"+}
+
+function testme() {
+ [-first_call-]{+firstCall+}();
+ [-if-]{+while+} (a [-==-]{+!=+} b) {
+ if (![-second_call())-]{+second_var)+} {
+ third_call{+() && fourth_call() \+}
+{+ || fifth_call+}();
+ }
+ }
+ return 42;
--- /dev/null
+diff --git a/test.txt b/test.txt
+--- a/test.txt
++++ b/test.txt
+@@ -1,21 +1,22 @@
+Tests
+[-=====-]{+====+}
+
+[-Simple-]{+Short+} sentence with[-a few-] words[-.-]{+!+}
+
+Longer sentence[-with-] even more words[-..-]{+,+} ain't that nice[-?-]{+!+}
+
+And [-another-]{+other+} one, just testing.
+
+option: {+new+} value
+option-two: {+new-+}value-two
+option-three: {+"+}value-three{+"+}
+
+function testme() {
+ [-first_call-]{+firstCall+}();
+ [-if-]{+while+} (a [-==-]{+!=+} b) {
+ if (![-second_call())-]{+second_var)+} {
+ third_call{+() && fourth_call() \+}
+{+ || fifth_call+}();
+ }
+ }
+ return 42;
--- /dev/null
+#!/bin/sh
+
+# Small test file to check different --word-diff-regex settings in Git.
+
+# Copyright (C) 2012 Simon Ruderich
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+set -e
+
+git_diff() {
+ git diff --color=never --word-diff=plain --word-diff-regex="$1" \
+ | grep -v '^index ' > "result-$2.txt"
+ diff -u "../expected-$2.txt" "result-$2.txt"
+}
+
+
+# Setup test directory/files.
+mkdir test
+cd test
+
+git init > /dev/null
+cat > test.txt <<EOF
+Tests
+=====
+
+Simple sentence with a few words.
+
+Longer sentence with even more words .. ain't that nice?
+
+And another one, just testing.
+
+option: value
+option-two: value-two
+option-three: value-three
+
+function testme() {
+ first_call();
+ if (a == b) {
+ if (!second_call()) {
+ third_call();
+ }
+ }
+ return 42;
+}
+EOF
+git add test.txt
+git commit -m 'Initial commit.' > /dev/null
+
+cat > test.txt <<EOF
+Tests
+====
+
+Short sentence with words!
+
+Longer sentence even more words, ain't that nice!
+
+And other one, just testing.
+
+option: new value
+option-two: new-value-two
+option-three: "value-three"
+
+function testme() {
+ firstCall();
+ while (a != b) {
+ if (!second_var) {
+ third_call() && fourth_call() \\
+ || fifth_call();
+ }
+ }
+ return 42;
+}
+EOF
+
+
+git_diff '' empty
+
+git_diff '[^[:space:]]+' nonspaces
+
+git_diff '[a-zA-Z0-9_]|[^a-zA-Z0-9_]' word-nonword
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]' words-nonword
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+' words-nonwords
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+' words-nonwordspaces
+
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_]+|[ ]+' words-nonwords-spaces
+git_diff '[a-zA-Z0-9_]+|[^a-zA-Z0-9_ ]+|[ ]+' words-nonwordspaces-spaces
+
+
+# Remove test directory after successful testing.
+rm -rf ../test