Sync with 2.38.5
[git.git] / t / t6439-merge-co-error-msgs.sh
blob52cf0c87690be83e758b97c12b0ab00fa77613a2
1 #!/bin/sh
3 test_description='unpack-trees error messages'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
11 test_expect_success 'setup' '
12 echo one >one &&
13 git add one &&
14 git commit -a -m First &&
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 &&
24 git checkout main &&
25 echo other >two &&
26 echo other >three &&
27 echo other >four &&
28 echo other >five
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
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 &&
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 ${GIT_TEST_MERGE_ALGORITHM:-ort} failed." >>expect &&
51 test_cmp out2 expect &&
52 git reset --hard HEAD^
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
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 &&
72 test_cmp out expect
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
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
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
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
111 cat >expect <<\EOF
112 error: Updating the following directories would lose untracked files in them:
114 rep2
116 Aborting
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
142 test_done