summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-12-19 19:33:56 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-19 19:33:56 (GMT)
commitd7c6c2369ac21141b7c6cceaebc6414ec3da14ad (patch)
tree9aa0b15668a5bffa1f05e766eebab1d3cbafb380 /t
parent6d2c4619a59d53325e6de2265205c407767bde9d (diff)
parent2477ab2ea8651920a9909f6d05b15ad9004a6c64 (diff)
downloadgit-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.zip
git-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.tar.gz
git-d7c6c2369ac21141b7c6cceaebc6414ec3da14ad.tar.bz2
Merge branch 'jt/diff-anchored-patience'
"git diff" learned a variant of the "--patience" algorithm, to which the user can specify which 'unique' line to be used as anchoring points. * jt/diff-anchored-patience: diff: support anchoring line(s)
Diffstat (limited to 't')
-rwxr-xr-xt/t4065-diff-anchored.sh94
1 files changed, 94 insertions, 0 deletions
diff --git a/t/t4065-diff-anchored.sh b/t/t4065-diff-anchored.sh
new file mode 100755
index 0000000..b3f510f
--- /dev/null
+++ b/t/t4065-diff-anchored.sh
@@ -0,0 +1,94 @@
+#!/bin/sh
+
+test_description='anchored diff algorithm'
+
+. ./test-lib.sh
+
+test_expect_success '--anchored' '
+ printf "a\nb\nc\n" >pre &&
+ printf "c\na\nb\n" >post &&
+
+ # normally, c is moved to produce the smallest diff
+ test_expect_code 1 git diff --no-index pre post >diff &&
+ grep "^+c" diff &&
+
+ # with anchor, a is moved
+ test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
+ grep "^+a" diff
+'
+
+test_expect_success '--anchored multiple' '
+ printf "a\nb\nc\nd\ne\nf\n" >pre &&
+ printf "c\na\nb\nf\nd\ne\n" >post &&
+
+ # with 1 anchor, c is not moved, but f is moved
+ test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
+ grep "^+a" diff && # a is moved instead of c
+ grep "^+f" diff &&
+
+ # with 2 anchors, c and f are not moved
+ test_expect_code 1 git diff --no-index --anchored=c --anchored=f pre post >diff &&
+ grep "^+a" diff &&
+ grep "^+d" diff # d is moved instead of f
+'
+
+test_expect_success '--anchored with nonexistent line has no effect' '
+ printf "a\nb\nc\n" >pre &&
+ printf "c\na\nb\n" >post &&
+
+ test_expect_code 1 git diff --no-index --anchored=x pre post >diff &&
+ grep "^+c" diff
+'
+
+test_expect_success '--anchored with non-unique line has no effect' '
+ printf "a\nb\nc\nd\ne\nc\n" >pre &&
+ printf "c\na\nb\nc\nd\ne\n" >post &&
+
+ test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
+ grep "^+c" diff
+'
+
+test_expect_success 'diff still produced with impossible multiple --anchored' '
+ printf "a\nb\nc\n" >pre &&
+ printf "c\na\nb\n" >post &&
+
+ test_expect_code 1 git diff --no-index --anchored=a --anchored=c pre post >diff &&
+ mv post expected_post &&
+
+ # Ensure that the diff is correct by applying it and then
+ # comparing the result with the original
+ git apply diff &&
+ diff expected_post post
+'
+
+test_expect_success 'later algorithm arguments override earlier ones' '
+ printf "a\nb\nc\n" >pre &&
+ printf "c\na\nb\n" >post &&
+
+ test_expect_code 1 git diff --no-index --patience --anchored=c pre post >diff &&
+ grep "^+a" diff &&
+
+ test_expect_code 1 git diff --no-index --anchored=c --patience pre post >diff &&
+ grep "^+c" diff &&
+
+ test_expect_code 1 git diff --no-index --histogram --anchored=c pre post >diff &&
+ grep "^+a" diff &&
+
+ test_expect_code 1 git diff --no-index --anchored=c --histogram pre post >diff &&
+ grep "^+c" diff
+'
+
+test_expect_success '--anchored works with other commands like "git show"' '
+ printf "a\nb\nc\n" >file &&
+ git add file &&
+ git commit -m foo &&
+ printf "c\na\nb\n" >file &&
+ git add file &&
+ git commit -m foo &&
+
+ # with anchor, a is moved
+ git show --patience --anchored=c >diff &&
+ grep "^+a" diff
+'
+
+test_done