]>
Commit | Line | Data |
---|---|---|
2477ab2e JT |
1 | #!/bin/sh |
2 | ||
3 | test_description='anchored diff algorithm' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success '--anchored' ' | |
8 | printf "a\nb\nc\n" >pre && | |
9 | printf "c\na\nb\n" >post && | |
10 | ||
11 | # normally, c is moved to produce the smallest diff | |
12 | test_expect_code 1 git diff --no-index pre post >diff && | |
13 | grep "^+c" diff && | |
14 | ||
15 | # with anchor, a is moved | |
16 | test_expect_code 1 git diff --no-index --anchored=c pre post >diff && | |
17 | grep "^+a" diff | |
18 | ' | |
19 | ||
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 && | |
23 | ||
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 | |
27 | grep "^+f" diff && | |
28 | ||
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 && | |
31 | grep "^+a" diff && | |
32 | grep "^+d" diff # d is moved instead of f | |
33 | ' | |
34 | ||
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 && | |
38 | ||
39 | test_expect_code 1 git diff --no-index --anchored=x pre post >diff && | |
40 | grep "^+c" diff | |
41 | ' | |
42 | ||
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 && | |
46 | ||
47 | test_expect_code 1 git diff --no-index --anchored=c pre post >diff && | |
48 | grep "^+c" diff | |
49 | ' | |
50 | ||
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 && | |
54 | ||
55 | test_expect_code 1 git diff --no-index --anchored=a --anchored=c pre post >diff && | |
56 | mv post expected_post && | |
57 | ||
58 | # Ensure that the diff is correct by applying it and then | |
59 | # comparing the result with the original | |
60 | git apply diff && | |
61 | diff expected_post post | |
62 | ' | |
63 | ||
64 | test_expect_success 'later algorithm arguments override earlier ones' ' | |
65 | printf "a\nb\nc\n" >pre && | |
66 | printf "c\na\nb\n" >post && | |
67 | ||
68 | test_expect_code 1 git diff --no-index --patience --anchored=c pre post >diff && | |
69 | grep "^+a" diff && | |
70 | ||
71 | test_expect_code 1 git diff --no-index --anchored=c --patience pre post >diff && | |
72 | grep "^+c" diff && | |
73 | ||
74 | test_expect_code 1 git diff --no-index --histogram --anchored=c pre post >diff && | |
75 | grep "^+a" diff && | |
76 | ||
77 | test_expect_code 1 git diff --no-index --anchored=c --histogram pre post >diff && | |
78 | grep "^+c" diff | |
79 | ' | |
80 | ||
81 | test_expect_success '--anchored works with other commands like "git show"' ' | |
82 | printf "a\nb\nc\n" >file && | |
83 | git add file && | |
84 | git commit -m foo && | |
85 | printf "c\na\nb\n" >file && | |
86 | git add file && | |
87 | git commit -m foo && | |
88 | ||
89 | # with anchor, a is moved | |
90 | git show --patience --anchored=c >diff && | |
91 | grep "^+a" diff | |
92 | ' | |
93 | ||
94 | test_done |