]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6439-merge-co-error-msgs.sh
merge: do not abort early if one strategy fails to handle the merge
[thirdparty/git.git] / t / t6439-merge-co-error-msgs.sh
CommitLineData
e935e62a
DG
1#!/bin/sh
2
3test_description='unpack-trees error messages'
4
5902f5f4 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
e935e62a
DG
8. ./test-lib.sh
9
10
11test_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
31cat >expect <<\EOF
32error: The following untracked working tree files would be overwritten by merge:
e935e62a 33 five
7980872d
CB
34 four
35 three
36 two
c2691e2a 37Please move or remove them before you merge.
6f90969b 38Aborting
e935e62a
DG
39EOF
40
c5978a50 41test_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
55cat >expect <<\EOF
56error: Your local changes to the following files would be overwritten by merge:
e935e62a 57 four
7980872d
CB
58 three
59 two
c2691e2a 60Please commit your changes or stash them before you merge.
e935e62a
DG
61error: The following untracked working tree files would be overwritten by merge:
62 five
c2691e2a 63Please move or remove them before you merge.
6f90969b 64Aborting
e935e62a
DG
65EOF
66
67test_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
75cat >expect <<\EOF
76error: Your local changes to the following files would be overwritten by checkout:
e935e62a 77 rep/one
7980872d 78 rep/two
c2691e2a 79Please commit your changes or stash them before you switch branches.
6f90969b 80Aborting
e935e62a
DG
81EOF
82
83test_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
97cat >expect <<\EOF
98error: Your local changes to the following files would be overwritten by checkout:
e935e62a 99 rep/one
7980872d 100 rep/two
c2691e2a 101Please commit your changes or stash them before you switch branches.
6f90969b 102Aborting
e935e62a
DG
103EOF
104
105test_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
111cat >expect <<\EOF
584f99c8 112error: Updating the following directories would lose untracked files in them:
e935e62a 113 rep
7980872d 114 rep2
e935e62a 115
6f90969b 116Aborting
e935e62a
DG
117EOF
118
119test_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
142test_done