]>
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 | ||
e935e62a DG |
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 | ||
5902f5f4 | 24 | git checkout main && |
e935e62a DG |
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: | |
e935e62a | 33 | five |
7980872d CB |
34 | four |
35 | three | |
36 | two | |
c2691e2a | 37 | Please move or remove them before you merge. |
6f90969b | 38 | Aborting |
e935e62a DG |
39 | EOF |
40 | ||
c5978a50 | 41 | test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' ' |
e935e62a | 42 | test_must_fail git merge branch 2>out && |
1108cea7 | 43 | test_cmp out expect && |
c5978a50 MM |
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 | ) && | |
8f240b8b | 50 | echo "Merge with strategy ${GIT_TEST_MERGE_ALGORITHM:-ort} failed." >>expect && |
1108cea7 | 51 | test_cmp out2 expect && |
c5978a50 | 52 | git reset --hard HEAD^ |
e935e62a DG |
53 | ' |
54 | ||
55 | cat >expect <<\EOF | |
56 | error: Your local changes to the following files would be overwritten by merge: | |
e935e62a | 57 | four |
7980872d CB |
58 | three |
59 | two | |
c2691e2a | 60 | Please commit your changes or stash them before you merge. |
e935e62a DG |
61 | error: The following untracked working tree files would be overwritten by merge: |
62 | five | |
c2691e2a | 63 | Please move or remove them before you merge. |
6f90969b | 64 | Aborting |
e935e62a DG |
65 | EOF |
66 | ||
67 | test_expect_success 'untracked files or local changes ovewritten by merge' ' | |
68 | git add two && | |
69 | git add three && | |
70 | git add four && | |
71 | test_must_fail git merge branch 2>out && | |
1108cea7 | 72 | test_cmp out expect |
e935e62a DG |
73 | ' |
74 | ||
75 | cat >expect <<\EOF | |
76 | error: Your local changes to the following files would be overwritten by checkout: | |
e935e62a | 77 | rep/one |
7980872d | 78 | rep/two |
c2691e2a | 79 | Please commit your changes or stash them before you switch branches. |
6f90969b | 80 | Aborting |
e935e62a DG |
81 | EOF |
82 | ||
83 | test_expect_success 'cannot switch branches because of local changes' ' | |
84 | git add five && | |
85 | mkdir rep && | |
86 | echo one >rep/one && | |
87 | echo two >rep/two && | |
88 | git add rep/one rep/two && | |
89 | git commit -m Fourth && | |
5902f5f4 | 90 | git checkout main && |
e935e62a DG |
91 | echo uno >rep/one && |
92 | echo dos >rep/two && | |
93 | test_must_fail git checkout branch 2>out && | |
1108cea7 | 94 | test_cmp out expect |
e935e62a DG |
95 | ' |
96 | ||
97 | cat >expect <<\EOF | |
98 | error: Your local changes to the following files would be overwritten by checkout: | |
e935e62a | 99 | rep/one |
7980872d | 100 | rep/two |
c2691e2a | 101 | Please commit your changes or stash them before you switch branches. |
6f90969b | 102 | Aborting |
e935e62a DG |
103 | EOF |
104 | ||
105 | test_expect_success 'not uptodate file porcelain checkout error' ' | |
106 | git add rep/one rep/two && | |
107 | test_must_fail git checkout branch 2>out && | |
1108cea7 | 108 | test_cmp out expect |
e935e62a DG |
109 | ' |
110 | ||
111 | cat >expect <<\EOF | |
584f99c8 | 112 | error: Updating the following directories would lose untracked files in them: |
e935e62a | 113 | rep |
7980872d | 114 | rep2 |
e935e62a | 115 | |
6f90969b | 116 | Aborting |
e935e62a DG |
117 | EOF |
118 | ||
119 | test_expect_success 'not_uptodate_dir porcelain checkout error' ' | |
120 | git init uptodate && | |
121 | cd uptodate && | |
122 | mkdir rep && | |
123 | mkdir rep2 && | |
124 | touch rep/foo && | |
125 | touch rep2/foo && | |
126 | git add rep/foo rep2/foo && | |
127 | git commit -m init && | |
128 | git checkout -b branch && | |
129 | git rm rep -r && | |
130 | git rm rep2 -r && | |
131 | >rep && | |
132 | >rep2 && | |
64d1022e | 133 | git add rep rep2 && |
e935e62a | 134 | git commit -m "added test as a file" && |
5902f5f4 | 135 | git checkout main && |
e935e62a DG |
136 | >rep/untracked-file && |
137 | >rep2/untracked-file && | |
138 | test_must_fail git checkout branch 2>out && | |
1108cea7 | 139 | test_cmp out ../expect |
e935e62a DG |
140 | ' |
141 | ||
142 | test_done |