Git fork
at reftables-rust 190 lines 4.9 kB view raw
1#!/bin/sh 2 3test_description='Return value of diffs' 4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8. ./test-lib.sh 9 10test_expect_success 'setup' ' 11 echo "1 " >a && 12 git add . && 13 git commit -m zeroth && 14 echo 1 >a && 15 git add . && 16 git commit -m first && 17 echo 2 >b && 18 git add . && 19 git commit -a -m second 20' 21 22test_expect_success 'git diff --quiet -w HEAD^^ HEAD^' ' 23 git diff --quiet -w HEAD^^ HEAD^ 24' 25 26test_expect_success 'git diff --quiet HEAD^^ HEAD^' ' 27 test_must_fail git diff --quiet HEAD^^ HEAD^ 28' 29 30test_expect_success 'git diff --quiet -w HEAD^ HEAD' ' 31 test_must_fail git diff --quiet -w HEAD^ HEAD 32' 33 34test_expect_success 'git diff-tree HEAD^ HEAD' ' 35 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD 36' 37test_expect_success 'git diff-tree HEAD^ HEAD -- a' ' 38 git diff-tree --exit-code HEAD^ HEAD -- a 39' 40test_expect_success 'git diff-tree HEAD^ HEAD -- b' ' 41 test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b 42' 43test_expect_success 'echo HEAD | git diff-tree --stdin' ' 44 echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin 45' 46test_expect_success 'git diff-tree HEAD HEAD' ' 47 git diff-tree --exit-code HEAD HEAD 48' 49test_expect_success 'git diff-files' ' 50 git diff-files --exit-code 51' 52test_expect_success 'git diff-index --cached HEAD' ' 53 git diff-index --exit-code --cached HEAD 54' 55test_expect_success 'git diff-index --cached HEAD^' ' 56 test_expect_code 1 git diff-index --exit-code --cached HEAD^ 57' 58test_expect_success 'git diff-index --cached HEAD^' ' 59 echo text >>b && 60 echo 3 >c && 61 git add . && 62 test_expect_code 1 git diff-index --exit-code --cached HEAD^ 63' 64test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' ' 65 git commit -m "text in b" && 66 test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b 67' 68test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' ' 69 git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b 70' 71test_expect_success 'git diff-files' ' 72 echo 3 >>c && 73 test_expect_code 1 git diff-files --exit-code 74' 75test_expect_success 'git diff-index --cached HEAD' ' 76 git update-index c && 77 test_expect_code 1 git diff-index --exit-code --cached HEAD 78' 79 80test_expect_success '--check --exit-code returns 0 for no difference' ' 81 82 git diff --check --exit-code 83 84' 85 86test_expect_success '--check --exit-code returns 1 for a clean difference' ' 87 88 echo "good" > a && 89 test_expect_code 1 git diff --check --exit-code 90 91' 92 93test_expect_success '--check --exit-code returns 3 for a dirty difference' ' 94 95 echo "bad " >> a && 96 test_expect_code 3 git diff --check --exit-code 97 98' 99 100test_expect_success '--check with --no-pager returns 2 for dirty difference' ' 101 102 test_expect_code 2 git --no-pager diff --check 103 104' 105 106test_expect_success 'check should test not just the last line' ' 107 echo "" >>a && 108 test_expect_code 2 git --no-pager diff --check 109 110' 111 112test_expect_success 'check detects leftover conflict markers' ' 113 git reset --hard && 114 git checkout HEAD^ && 115 echo binary >>b && 116 git commit -m "side" b && 117 test_must_fail git merge main && 118 git add b && 119 test_expect_code 2 git --no-pager diff --cached --check >test.out && 120 test 3 = $(grep "conflict marker" test.out | wc -l) && 121 git reset --hard 122' 123 124test_expect_success 'check honors conflict marker length' ' 125 git reset --hard && 126 echo ">>>>>>> boo" >>b && 127 echo "======" >>a && 128 git diff --check a && 129 test_expect_code 2 git diff --check b && 130 git reset --hard && 131 echo ">>>>>>>> boo" >>b && 132 echo "========" >>a && 133 git diff --check && 134 echo "b conflict-marker-size=8" >.gitattributes && 135 test_expect_code 2 git diff --check b && 136 git diff --check a && 137 git reset --hard 138' 139 140test_expect_success 'option errors are not confused by --exit-code' ' 141 test_must_fail git diff --exit-code --nonsense 2>err && 142 grep '^usage:' err 143' 144 145for option in --exit-code --quiet 146do 147 test_expect_success "git diff $option returns 1 for changed binary file" " 148 test_when_finished 'rm -f .gitattributes' && 149 git reset --hard && 150 echo a binary >.gitattributes && 151 echo 2 >>a && 152 test_expect_code 1 git diff $option 153 " 154 155 test_expect_success "git diff $option returns 1 for copied file" " 156 git reset --hard && 157 cp a copy && 158 git add copy && 159 test_expect_code 1 git diff $option --cached --find-copies-harder 160 " 161 162 test_expect_success "git diff $option returns 1 for renamed file" " 163 git reset --hard && 164 git mv a renamed && 165 test_expect_code 1 git diff $option --cached 166 " 167done 168 169test_expect_success 'setup dirty subrepo' ' 170 git reset --hard && 171 test_create_repo subrepo && 172 test_commit -C subrepo subrepo-file && 173 test_tick && 174 git add subrepo && 175 git commit -m subrepo && 176 test_commit -C subrepo another-subrepo-file 177' 178 179for option in --exit-code --quiet 180do 181 for submodule_format in diff log short 182 do 183 opts="$option --submodule=$submodule_format" && 184 test_expect_success "git diff $opts returns 1 for dirty subrepo" " 185 test_expect_code 1 git diff $opts 186 " 187 done 188done 189 190test_done