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