summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-02-19 17:27:56 -0800
committerJunio C Hamano <gitster@pobox.com>2012-02-19 18:05:01 -0800
commite325bf7d045de2976cc3c048922f1b727a468d41 (patch)
treeee07a3c5f66b06e7584662b4b25691d0769619f5
parent040b49b42600f4a805b9b55246d6d75c208fc269 (diff)
downloadgit-e325bf7d045de2976cc3c048922f1b727a468d41.tar.gz
diff: --ignore-case
Teach the front-end to flip XDF_IGNORE_CASE bit with the options GNU diff uses. Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--Documentation/diff-options.txt4
-rw-r--r--diff.c2
-rw-r--r--t/lib-diff-alternative.sh45
-rwxr-xr-xt/t4033-diff-patience.sh6
-rwxr-xr-xt/t4050-diff-histogram.sh2
5 files changed, 57 insertions, 2 deletions
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 9f7cba2be6..791e07feaf 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -404,6 +404,10 @@ endif::git-format-patch[]
differences even if one line has whitespace where the other
line has none.
+--ignore-case::
+ Ignore changes in case only; only ASCII alphabet is supported for
+ now.
+
--inter-hunk-context=<lines>::
Show the context between diff hunks, up to the specified number
of lines, thereby fusing hunks that are close to each other.
diff --git a/diff.c b/diff.c
index 87b2ec1393..d7604b7195 100644
--- a/diff.c
+++ b/diff.c
@@ -3399,6 +3399,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
DIFF_XDL_SET(options, IGNORE_WHITESPACE_CHANGE);
else if (!strcmp(arg, "--ignore-space-at-eol"))
DIFF_XDL_SET(options, IGNORE_WHITESPACE_AT_EOL);
+ else if (!strcmp(arg, "--ignore-case"))
+ DIFF_XDL_SET(options, IGNORE_CASE);
else if (!strcmp(arg, "--patience"))
options->xdl_opts = DIFF_WITH_ALG(options, PATIENCE_DIFF);
else if (!strcmp(arg, "--histogram"))
diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh
index 75ffd9174f..45c665e90d 100644
--- a/t/lib-diff-alternative.sh
+++ b/t/lib-diff-alternative.sh
@@ -104,8 +104,9 @@ EOF
STRATEGY=$1
+ cmd='git diff --no-index'
test_expect_success "$STRATEGY diff" '
- test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output &&
+ test_must_fail $cmd ${STRATEGY:+"--$STRATEGY"} file1 file2 >output &&
test_cmp expect output
'
@@ -157,9 +158,49 @@ EOF
STRATEGY=$1
+ cmd='git diff --no-index'
test_expect_success 'completely different files' '
- test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output &&
+
+ test_must_fail $cmd ${STRATEGY:+"--$STRATEGY"} uniq1 uniq2 >output &&
test_cmp expect output
'
}
+test_diff_ignore () {
+
+ STRATEGY=$1
+
+ echo "A quick brown fox" >test.0
+ echo "A quick brown fox" >test-b
+ echo " A quick brownfox" >test-w
+ echo "A quick brown fox " >test--ignore-space-at-eol
+ echo "A Quick Brown Fox" >test--ignore-case
+ echo "A Quick Brown Fox" >test--ignore-case-b
+ echo "A quick brown fox jumps" >test
+ cases="-b -w --ignore-space-at-eol --ignore-case"
+
+ if test -z "$STRATEGY"
+ then
+ label=baseline
+ else
+ label=$STRATEGY
+ fi
+
+ cmd="git diff --no-index ${STRATEGY:+--$STRATEGY}"
+
+ test_expect_success "$label diff" '
+ test_must_fail $cmd test.0 test
+ '
+ for case in $cases
+ do
+ test_expect_success "$label diff $case" '
+ $cmd $case test.0 test$case &&
+ test_must_fail $cmd test.0 test
+ '
+ done
+
+ test_expect_success "$label diff -b --ignore-case" '
+ $cmd -b --ignore-case test.0 test--ignore-case-b
+ '
+
+}
diff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh
index 3c9932edf3..c7f8c6cedf 100755
--- a/t/t4033-diff-patience.sh
+++ b/t/t4033-diff-patience.sh
@@ -5,8 +5,14 @@ test_description='patience diff algorithm'
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff-alternative.sh
+# baseline
+test_diff_unique ""
+test_diff_ignore ""
+
test_diff_frobnitz "patience"
test_diff_unique "patience"
+test_diff_ignore "patience"
+
test_done
diff --git a/t/t4050-diff-histogram.sh b/t/t4050-diff-histogram.sh
index fd3e86a74f..98c66860e6 100755
--- a/t/t4050-diff-histogram.sh
+++ b/t/t4050-diff-histogram.sh
@@ -9,4 +9,6 @@ test_diff_frobnitz "histogram"
test_diff_unique "histogram"
+test_diff_ignore "histogram"
+
test_done