]>
git.ipfire.org Git - thirdparty/git.git/blob - t/t4065-diff-anchored.sh
3 test_description
='anchored diff algorithm'
7 test_expect_success
'--anchored' '
8 printf "a\nb\nc\n" >pre &&
9 printf "c\na\nb\n" >post &&
11 # normally, c is moved to produce the smallest diff
12 test_expect_code 1 git diff --no-index pre post >diff &&
15 # with anchor, a is moved
16 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
20 test_expect_success
'--anchored multiple' '
21 printf "a\nb\nc\nd\ne\nf\n" >pre &&
22 printf "c\na\nb\nf\nd\ne\n" >post &&
24 # with 1 anchor, c is not moved, but f is moved
25 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
26 grep "^+a" diff && # a is moved instead of c
29 # with 2 anchors, c and f are not moved
30 test_expect_code 1 git diff --no-index --anchored=c --anchored=f pre post >diff &&
32 grep "^+d" diff # d is moved instead of f
35 test_expect_success
'--anchored with nonexistent line has no effect' '
36 printf "a\nb\nc\n" >pre &&
37 printf "c\na\nb\n" >post &&
39 test_expect_code 1 git diff --no-index --anchored=x pre post >diff &&
43 test_expect_success
'--anchored with non-unique line has no effect' '
44 printf "a\nb\nc\nd\ne\nc\n" >pre &&
45 printf "c\na\nb\nc\nd\ne\n" >post &&
47 test_expect_code 1 git diff --no-index --anchored=c pre post >diff &&
51 test_expect_success
'diff still produced with impossible multiple --anchored' '
52 printf "a\nb\nc\n" >pre &&
53 printf "c\na\nb\n" >post &&
55 test_expect_code 1 git diff --no-index --anchored=a --anchored=c pre post >diff &&
56 mv post expected_post &&
58 # Ensure that the diff is correct by applying it and then
59 # comparing the result with the original
61 diff expected_post post
64 test_expect_success
'later algorithm arguments override earlier ones' '
65 printf "a\nb\nc\n" >pre &&
66 printf "c\na\nb\n" >post &&
68 test_expect_code 1 git diff --no-index --patience --anchored=c pre post >diff &&
71 test_expect_code 1 git diff --no-index --anchored=c --patience pre post >diff &&
74 test_expect_code 1 git diff --no-index --histogram --anchored=c pre post >diff &&
77 test_expect_code 1 git diff --no-index --anchored=c --histogram pre post >diff &&
81 test_expect_success
'--anchored works with other commands like "git show"' '
82 printf "a\nb\nc\n" >file &&
85 printf "c\na\nb\n" >file &&
89 # with anchor, a is moved
90 git show --patience --anchored=c >diff &&