]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | ||
3 | test_description='unpack-trees error messages' | |
4 | ||
5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | |
6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | |
7 | ||
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 | ||
24 | git checkout main && | |
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: | |
33 | five | |
34 | four | |
35 | three | |
36 | two | |
37 | Please move or remove them before you merge. | |
38 | Aborting | |
39 | EOF | |
40 | ||
41 | test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' ' | |
42 | test_must_fail git merge branch 2>out && | |
43 | test_cmp out expect && | |
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 | ) && | |
50 | echo "Merge with strategy ort failed." >>expect && | |
51 | test_cmp out2 expect && | |
52 | git reset --hard HEAD^ | |
53 | ' | |
54 | ||
55 | cat >expect <<\EOF | |
56 | error: Your local changes to the following files would be overwritten by merge: | |
57 | four | |
58 | three | |
59 | two | |
60 | Please commit your changes or stash them before you merge. | |
61 | error: The following untracked working tree files would be overwritten by merge: | |
62 | five | |
63 | Please move or remove them before you merge. | |
64 | Aborting | |
65 | EOF | |
66 | ||
67 | test_expect_success 'untracked files or local changes overwritten by merge' ' | |
68 | git add two && | |
69 | git add three && | |
70 | git add four && | |
71 | test_must_fail git merge branch 2>out && | |
72 | test_cmp out expect | |
73 | ' | |
74 | ||
75 | cat >expect <<\EOF | |
76 | error: Your local changes to the following files would be overwritten by checkout: | |
77 | rep/one | |
78 | rep/two | |
79 | Please commit your changes or stash them before you switch branches. | |
80 | Aborting | |
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 && | |
90 | git checkout main && | |
91 | echo uno >rep/one && | |
92 | echo dos >rep/two && | |
93 | test_must_fail git checkout branch 2>out && | |
94 | test_cmp out expect | |
95 | ' | |
96 | ||
97 | cat >expect <<\EOF | |
98 | error: Your local changes to the following files would be overwritten by checkout: | |
99 | rep/one | |
100 | rep/two | |
101 | Please commit your changes or stash them before you switch branches. | |
102 | Aborting | |
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 && | |
108 | test_cmp out expect | |
109 | ' | |
110 | ||
111 | cat >expect <<\EOF | |
112 | error: Updating the following directories would lose untracked files in them: | |
113 | rep | |
114 | rep2 | |
115 | ||
116 | Aborting | |
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 && | |
133 | git add rep rep2 && | |
134 | git commit -m "added test as a file" && | |
135 | git checkout main && | |
136 | >rep/untracked-file && | |
137 | >rep2/untracked-file && | |
138 | test_must_fail git checkout branch 2>out && | |
139 | test_cmp out ../expect | |
140 | ' | |
141 | ||
142 | test_done |