]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6439-merge-co-error-msgs.sh
Merge branch 'rj/add-i-leak-fix'
[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
345e216f 8TEST_PASSES_SANITIZE_LEAK=true
e935e62a
DG
9. ./test-lib.sh
10
11
12test_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
32cat >expect <<\EOF
33error: The following untracked working tree files would be overwritten by merge:
e935e62a 34 five
7980872d
CB
35 four
36 three
37 two
c2691e2a 38Please move or remove them before you merge.
6f90969b 39Aborting
e935e62a
DG
40EOF
41
c5978a50 42test_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
56cat >expect <<\EOF
57error: Your local changes to the following files would be overwritten by merge:
e935e62a 58 four
7980872d
CB
59 three
60 two
c2691e2a 61Please commit your changes or stash them before you merge.
e935e62a
DG
62error: The following untracked working tree files would be overwritten by merge:
63 five
c2691e2a 64Please move or remove them before you merge.
6f90969b 65Aborting
e935e62a
DG
66EOF
67
68test_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
76cat >expect <<\EOF
77error: Your local changes to the following files would be overwritten by checkout:
e935e62a 78 rep/one
7980872d 79 rep/two
c2691e2a 80Please commit your changes or stash them before you switch branches.
6f90969b 81Aborting
e935e62a
DG
82EOF
83
84test_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
98cat >expect <<\EOF
99error: Your local changes to the following files would be overwritten by checkout:
e935e62a 100 rep/one
7980872d 101 rep/two
c2691e2a 102Please commit your changes or stash them before you switch branches.
6f90969b 103Aborting
e935e62a
DG
104EOF
105
106test_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
112cat >expect <<\EOF
584f99c8 113error: Updating the following directories would lose untracked files in them:
e935e62a 114 rep
7980872d 115 rep2
e935e62a 116
6f90969b 117Aborting
e935e62a
DG
118EOF
119
120test_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
143test_done