1#!/bin/sh 2 3test_description='unpack-trees error messages' 4 5. ./test-lib.sh 6 7 8test_expect_success 'setup'' 9 echo one >one && 10 git add one && 11 git commit -a -m First && 12 13 git checkout -b branch && 14 echo two >two && 15 echo three >three && 16 echo four >four && 17 echo five >five && 18 git add two three four five && 19 git commit -m Second && 20 21 git checkout master && 22 echo other >two && 23 echo other >three && 24 echo other >four && 25 echo other >five 26' 27 28cat>expect <<\EOF 29error: The following untracked working tree files would be overwritten by merge: 30 two 31 three 32 four 33 five 34Please move or remove them before you can merge. 35EOF 36 37test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)'' 38 test_must_fail git merge branch 2>out && 39 test_cmp out expect && 40 git commit --allow-empty -m empty && 41 ( 42 GIT_MERGE_VERBOSITY=0 && 43 export GIT_MERGE_VERBOSITY && 44 test_must_fail git merge branch 2>out2 45 ) && 46 test_cmp out2 expect && 47 git reset --hard HEAD^ 48' 49 50cat>expect <<\EOF 51error: Your local changes to the following files would be overwritten by merge: 52 two 53 three 54 four 55Please, commit your changes or stash them before you can merge. 56error: The following untracked working tree files would be overwritten by merge: 57 five 58Please move or remove them before you can merge. 59EOF 60 61test_expect_success 'untracked files or local changes ovewritten by merge'' 62 git add two && 63 git add three && 64 git add four && 65 test_must_fail git merge branch 2>out && 66 test_cmp out expect 67' 68 69cat>expect <<\EOF 70error: Your local changes to the following files would be overwritten by checkout: 71 rep/two 72 rep/one 73Please, commit your changes or stash them before you can switch branches. 74EOF 75 76test_expect_success 'cannot switch branches because of local changes'' 77 git add five && 78 mkdir rep && 79 echo one >rep/one && 80 echo two >rep/two && 81 git add rep/one rep/two && 82 git commit -m Fourth && 83 git checkout master && 84 echo uno >rep/one && 85 echo dos >rep/two && 86 test_must_fail git checkout branch 2>out && 87 test_cmp out expect 88' 89 90cat>expect <<\EOF 91error: Your local changes to the following files would be overwritten by checkout: 92 rep/two 93 rep/one 94Please, commit your changes or stash them before you can switch branches. 95EOF 96 97test_expect_success 'not uptodate file porcelain checkout error'' 98 git add rep/one rep/two && 99 test_must_fail git checkout branch 2>out && 100 test_cmp out expect 101' 102 103cat>expect <<\EOF 104error: Updating the following directories would lose untracked files in it: 105 rep2 106 rep 107 108EOF 109 110test_expect_success 'not_uptodate_dir porcelain checkout error'' 111 git init uptodate && 112 cd uptodate && 113 mkdir rep && 114 mkdir rep2 && 115 touch rep/foo && 116 touch rep2/foo && 117 git add rep/foo rep2/foo && 118 git commit -m init && 119 git checkout -b branch && 120 git rm rep -r && 121 git rm rep2 -r && 122 >rep && 123 >rep2 && 124 git add rep rep2&& 125 git commit -m "added test as a file" && 126 git checkout master && 127 >rep/untracked-file && 128 >rep2/untracked-file && 129 test_must_fail git checkout branch 2>out && 130 test_cmp out ../expect 131' 132 133test_done