Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t4065-diff-anchored.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t4065-diff-anchored.sh` 94 lines ยท 2689 bytes Raw Blame History 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 test_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 test_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 test_grep "^+a" diff && # a is moved instead of c 27 test_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 test_grep "^+a" diff && 32 test_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 test_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 test_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 test_grep "^+a" diff && 70 71 test_expect_code 1 git diff --no-index --anchored=c --patience pre post >diff && 72 test_grep "^+c" diff && 73 74 test_expect_code 1 git diff --no-index --histogram --anchored=c pre post >diff && 75 test_grep "^+a" diff && 76 77 test_expect_code 1 git diff --no-index --anchored=c --histogram pre post >diff && 78 test_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 test_grep "^+a" diff 92 ' 93 94 test_done