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/t4051-diff-function-context.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 / t4051-diff-function-context.sh` 212 lines ยท 5644 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='diff function context' 4 5 . ./test-lib.sh 6 7 dir="$TEST_DIRECTORY/t4051" 8 9 commit_and_tag () { 10 tag=$1 && 11 shift && 12 git add "$@" && 13 test_tick && 14 git commit -m "$tag" && 15 git tag "$tag" 16 } 17 18 first_context_line () { 19 awk ' 20 found {print; exit} 21 /^@@/ {found = 1} 22 ' 23 } 24 25 last_context_line () { 26 sed -ne \$p 27 } 28 29 check_diff () { 30 name=$1 31 desc=$2 32 options="-W $3" 33 34 test_expect_success "$desc" ' 35 git diff $options "$name^" "$name" >"$name.diff" 36 ' 37 38 test_expect_success ' diff applies' ' 39 test_when_finished "git reset --hard" && 40 git checkout --detach "$name^" && 41 git apply --index "$name.diff" && 42 git diff --exit-code "$name" 43 ' 44 } 45 46 test_expect_success 'setup' ' 47 cat "$dir/includes.c" "$dir/dummy.c" "$dir/dummy.c" "$dir/hello.c" \ 48 "$dir/dummy.c" "$dir/dummy.c" >file.c && 49 commit_and_tag initial file.c && 50 51 grep -v "delete me from hello" file.c.new && 52 mv file.c.new file.c && 53 commit_and_tag changed_hello file.c && 54 55 grep -v "delete me from includes" file.c.new && 56 mv file.c.new file.c && 57 commit_and_tag changed_includes file.c && 58 59 cat "$dir/appended1.c" >>file.c && 60 commit_and_tag appended file.c && 61 62 cat "$dir/appended2.c" >>file.c && 63 commit_and_tag extended file.c && 64 65 grep -v "Begin of second part" file.c.new && 66 mv file.c.new file.c && 67 commit_and_tag long_common_tail file.c && 68 69 git checkout initial && 70 cat "$dir/hello.c" "$dir/dummy.c" >file.c && 71 commit_and_tag hello_dummy file.c && 72 73 # overlap function context of 1st change and -u context of 2nd change 74 grep -v "delete me from hello" <"$dir/hello.c" >file.c && 75 sed "2a\\ 76 extra line" <"$dir/dummy.c" >>file.c && 77 commit_and_tag changed_hello_dummy file.c && 78 79 git checkout initial && 80 grep -v "delete me from hello" file.c.new && 81 mv file.c.new file.c && 82 cat "$dir/appended1.c" >>file.c && 83 commit_and_tag changed_hello_appended file.c 84 ' 85 86 check_diff changed_hello 'changed function' 87 88 test_expect_success ' context includes comment' ' 89 test_grep "^ .*Hello comment" changed_hello.diff 90 ' 91 92 test_expect_success ' context includes begin' ' 93 test_grep "^ .*Begin of hello" changed_hello.diff 94 ' 95 96 test_expect_success ' context includes end' ' 97 test_grep "^ .*End of hello" changed_hello.diff 98 ' 99 100 test_expect_success ' context does not include other functions' ' 101 test $(grep -c "^[ +-].*Begin" changed_hello.diff) -le 1 102 ' 103 104 test_expect_success ' context does not include preceding empty lines' ' 105 test "$(first_context_line