Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='unpack-trees error messages' |
| 4 | |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | |
| 11 | test_expect_success 'setup' ' |
| 12 | echo one >one && |
| 13 | git add one && |
| 14 | git commit -a -m First && |
| 15 | |
| 16 | git checkout -b branch && |
| 17 | echo two >two && |
| 18 | echo three >three && |
| 19 | echo four >four && |
| 20 | echo five >five && |
| 21 | git add two three four five && |
| 22 | git commit -m Second && |
| 23 | |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 24 | git checkout main && |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 25 | echo other >two && |
| 26 | echo other >three && |
| 27 | echo other >four && |
| 28 | echo other >five |
| 29 | ' |
| 30 | |
| 31 | cat >expect <<\EOF |
| 32 | error: The following untracked working tree files would be overwritten by merge: |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 33 | five |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 34 | four |
| 35 | three |
| 36 | two |
Alex Henrie | c2691e2 | 2016-06-25 00:34:04 -0600 | [diff] [blame] | 37 | Please move or remove them before you merge. |
Michael J Gruber | 6f90969 | 2011-09-21 09:48:36 +0200 | [diff] [blame] | 38 | Aborting |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 39 | EOF |
| 40 | |
Matthieu Moy | c5978a5 | 2010-09-03 17:25:33 +0200 | [diff] [blame] | 41 | test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' ' |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 42 | test_must_fail git merge branch 2>out && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 43 | test_cmp out expect && |
Matthieu Moy | c5978a5 | 2010-09-03 17:25:33 +0200 | [diff] [blame] | 44 | git commit --allow-empty -m empty && |
| 45 | ( |
| 46 | GIT_MERGE_VERBOSITY=0 && |
| 47 | export GIT_MERGE_VERBOSITY && |
| 48 | test_must_fail git merge branch 2>out2 |
| 49 | ) && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 50 | test_cmp out2 expect && |
Matthieu Moy | c5978a5 | 2010-09-03 17:25:33 +0200 | [diff] [blame] | 51 | git reset --hard HEAD^ |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 52 | ' |
| 53 | |
| 54 | cat >expect <<\EOF |
| 55 | error: Your local changes to the following files would be overwritten by merge: |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 56 | four |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 57 | three |
| 58 | two |
Alex Henrie | c2691e2 | 2016-06-25 00:34:04 -0600 | [diff] [blame] | 59 | Please commit your changes or stash them before you merge. |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 60 | error: The following untracked working tree files would be overwritten by merge: |
| 61 | five |
Alex Henrie | c2691e2 | 2016-06-25 00:34:04 -0600 | [diff] [blame] | 62 | Please move or remove them before you merge. |
Michael J Gruber | 6f90969 | 2011-09-21 09:48:36 +0200 | [diff] [blame] | 63 | Aborting |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 64 | EOF |
| 65 | |
| 66 | test_expect_success 'untracked files or local changes ovewritten by merge' ' |
| 67 | git add two && |
| 68 | git add three && |
| 69 | git add four && |
| 70 | test_must_fail git merge branch 2>out && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 71 | test_cmp out expect |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 72 | ' |
| 73 | |
| 74 | cat >expect <<\EOF |
| 75 | error: Your local changes to the following files would be overwritten by checkout: |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 76 | rep/one |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 77 | rep/two |
Alex Henrie | c2691e2 | 2016-06-25 00:34:04 -0600 | [diff] [blame] | 78 | Please commit your changes or stash them before you switch branches. |
Michael J Gruber | 6f90969 | 2011-09-21 09:48:36 +0200 | [diff] [blame] | 79 | Aborting |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 80 | EOF |
| 81 | |
| 82 | test_expect_success 'cannot switch branches because of local changes' ' |
| 83 | git add five && |
| 84 | mkdir rep && |
| 85 | echo one >rep/one && |
| 86 | echo two >rep/two && |
| 87 | git add rep/one rep/two && |
| 88 | git commit -m Fourth && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 89 | git checkout main && |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 90 | echo uno >rep/one && |
| 91 | echo dos >rep/two && |
| 92 | test_must_fail git checkout branch 2>out && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 93 | test_cmp out expect |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 94 | ' |
| 95 | |
| 96 | cat >expect <<\EOF |
| 97 | error: Your local changes to the following files would be overwritten by checkout: |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 98 | rep/one |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 99 | rep/two |
Alex Henrie | c2691e2 | 2016-06-25 00:34:04 -0600 | [diff] [blame] | 100 | Please commit your changes or stash them before you switch branches. |
Michael J Gruber | 6f90969 | 2011-09-21 09:48:36 +0200 | [diff] [blame] | 101 | Aborting |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 102 | EOF |
| 103 | |
| 104 | test_expect_success 'not uptodate file porcelain checkout error' ' |
| 105 | git add rep/one rep/two && |
| 106 | test_must_fail git checkout branch 2>out && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 107 | test_cmp out expect |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 108 | ' |
| 109 | |
| 110 | cat >expect <<\EOF |
Stefan Beller | 584f99c | 2016-12-02 11:17:41 -0800 | [diff] [blame] | 111 | error: Updating the following directories would lose untracked files in them: |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 112 | rep |
Clemens Buchacher | 7980872 | 2010-11-15 20:52:19 +0100 | [diff] [blame] | 113 | rep2 |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 114 | |
Michael J Gruber | 6f90969 | 2011-09-21 09:48:36 +0200 | [diff] [blame] | 115 | Aborting |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 116 | EOF |
| 117 | |
| 118 | test_expect_success 'not_uptodate_dir porcelain checkout error' ' |
| 119 | git init uptodate && |
| 120 | cd uptodate && |
| 121 | mkdir rep && |
| 122 | mkdir rep2 && |
| 123 | touch rep/foo && |
| 124 | touch rep2/foo && |
| 125 | git add rep/foo rep2/foo && |
| 126 | git commit -m init && |
| 127 | git checkout -b branch && |
| 128 | git rm rep -r && |
| 129 | git rm rep2 -r && |
| 130 | >rep && |
| 131 | >rep2 && |
Andrei Rybak | 64d1022 | 2020-03-22 22:14:22 +0100 | [diff] [blame] | 132 | git add rep rep2 && |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 133 | git commit -m "added test as a file" && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 134 | git checkout main && |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 135 | >rep/untracked-file && |
| 136 | >rep2/untracked-file && |
| 137 | test_must_fail git checkout branch 2>out && |
Ævar Arnfjörð Bjarmason | 1108cea | 2021-02-11 02:53:53 +0100 | [diff] [blame] | 138 | test_cmp out ../expect |
Diane Gasselin | e935e62 | 2010-08-11 10:38:08 +0200 | [diff] [blame] | 139 | ' |
| 140 | |
| 141 | test_done |